在PHP中定义变量Get


Defining Variable Get in PHP

我只是个新手,还在学习PHP。

我试图使一个简单的PHP连接和做基本的语法插入,删除,选择和更新,但我遇到了一个错误Undefined Variable: Get in C:/wamp/www/sql。我错过什么了吗?

这是我得到的:

 <?php
$servername = "localhost";
$username = "root";
$password = "";
$port = "3306";
$dbname = "student";

$conn = mysqli_connect($servername, $username, $password, $dbname, $port);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
 }
$sql = "SELECT * FROM info";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
      echo "ID: " . $row["studentid"]. " Name: " . $row["fname"]. " " .         $row["lname"]." <a href = delete.php? uid=".$row["studentid"]."> Delete</a> |  
  <a href = test.php?     euid=".$row['studentid']."&elname".$row['lname']."&efname".$row['fname']."> Edit     </a> <br/>" ;
}
} else {
echo "0 results";
}
?>
<form action ="insert.php" method="POST">
<input type ="text" name="fname">
<input type ="text" name="lname">
<input type ="submit"value="Submit">
</form>
<form action ="update.php" method="POST">
<input type ="hidden" name="ID"<?php echo"value=".$GET["studentid"];?>> //I get the error from here
<input type ="text" name="fname"<?php echo"value=".$GET['fname'];?>>
<input type ="text"name="lname"<?php echo"value=".$GET['lname'];?>>. // until here
<input type ="submit"value="Update">
</form>

<?php
mysqli_close($conn);
?>
编辑:这是我遇到麻烦的另一个。我得到那里的错误Parse error: syntax error, unexpected '<' in如何修复它?在这部分代码中:
<?php
if(isset($_GET['xID']))
{
<form action ="update.php" method="POST">
<input type ="hidden" name="ID"<?php echo"value=".$_GET['xID'];?>>
<input type ="text" name="fname"<?php echo"value=".$_GET['xfname'];?>>
<input type ="text"name="lname"<?php echo"value=".$_GET['xlname'];?>>.
<input type ="submit"value="Update">
}
else
{
}
</form>
?>

您使用get是错误的,它不是$GET,它是$_GET,像这样更改您的代码。

<form action ="update.php" method="GET">
     <input type ="hidden" name="ID"<?php echo"value=".$_GET["studentid"];?>> //I get the error from here
     <input type ="text" name="fname"<?php echo"value=".$_GET['fname'];?>>
    <input type ="text"name="lname"<?php echo"value=".$_GET['lname'];?>>. // until here
     <input type ="submit"value="Update">
</form>

除了语法错误(它是$_GET而不是$GET),您还使用POST作为发送数据的方法,请务必了解GETPOST方法之间的差异。

您还应该知道,您可以使用use $_REQUEST来检索通过GETPOST发送的数据。

下面应该是正确的:

<form action ="update.php" method="GET">
     <input type ="hidden" name="ID"<?php echo"value=".$_REQUEST["studentid"];?>>
     <input type ="text" name="fname"<?php echo"value=".$_REQUEST['fname'];?>>
    <input type ="text"name="lname"<?php echo"value=".$_REQUEST['lname'];?>>.
     <input type ="submit"value="Update">
</form>