[英]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
如何解決它中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作為發送數據的方法,請務必了解GET
和POST
方法之間的區別。
您還應該知道可以使用$_REQUEST
來檢索通過GET
和POST
發送的數據。
以下應該是正確的:
<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.