简体   繁体   English

在PHP中定义变量Get

[英]Defining Variable Get in PHP

Im just new and still learning PHP. 我只是新手,还在学习PHP。

Im trying to make a simple PHP for connecting and doing basic syntax insert, delete,select and update but I encountered an error Undefined Variable: Get in C:/wamp/www/sql . 我正在尝试制作一个简单的PHP以连接和执行基本的语法插入,删除,选择和更新,但是遇到错误Undefined Variable: Get in C:/wamp/www/sql Is there something I missed? 有什么我想念的吗?

Here is what i got: 这是我得到的:

 <?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);
?>

Edit: Here is the other one im having trouble with.I get there error Parse error: syntax error, unexpected '<' in How to fix it?. 编辑:这是另一个我遇到麻烦的地方。我到那里了错误Parse error: syntax error, unexpected '<' in如何解决它中Parse error: syntax error, unexpected '<' in In this part of code: 在这部分代码中:

<?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>
?>

you using get as wrong, its not $GET , its $_GET , chenge your code like this. 您使用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>

In addition to the syntax error (it's $_GET and not $GET ), you are also using POST as method to send the data, be sure to learn the difference between GET and POST methods. 除了语法错误(是$_GET而不是$GET )之外,您还使用POST作为发送数据的方法,请务必了解GETPOST方法之间的区别。

You should also know that you can use use $_REQUEST to retrieve the data sent via both GET and POST . 您还应该知道可以使用$_REQUEST来检索通过GETPOST发送的数据。

The following should be correct: 以下应该是正确的:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM