PHP为下一个PHP获取数据

时间:2016-04-10 06:04:27

标签: php

我有PHP代码,我不知道它是否有效,所以我需要帮助看看它是否可行......

one.php

$var = 'Name_here';
echo '<input type="text" name="name12" value="'.$var.'", PHP_EO>';

two.php

include("shop.php");
$sname = $var;
$sql = "INSERT INTO Users (Username, Password, UserChanges, PIC) VALUES ('$sname', '$pass', '3', '0')";

这会有用吗?从另一个PHP表单获取文本框值谢谢!

1 个答案:

答案 0 :(得分:0)

One.php文件应该有以下代码

 <form action="two.php" method="post">     
    <?Php 
          $var = 'Name_here';
          echo '<input type="text" name="name" value="'.$var.'", PHP_EO>';
          echo '<input type="password" name="pass" value="'.$var.'", PHP_EO>';
    ?>

        

Two.php

include("shop.php");
$sname = $var;
$sql = "INSERT INTO Users (Username, Password, UserChanges, PIC) VALUES ('". $_REQUEST["name"] ."', '". $_REQUEST["pass"] ."', '3', '0')";

$servername = "localhost"; 
$username = "username";
$password = "password";

// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$conn->query($sql);

检查此代码。