更新php和Mysql中的数据

时间:2016-12-25 12:31:22

标签: php html mysql

我的代码有问题!!我写了它,但在运行中它告诉我是未定义的变量!!我不知道错误在哪里。请帮我。 据我所知,它已经在connection.php中定义。 的 updateform.php

<?php
include "connection.php"; 

?>
<!DOCTYPE html> 

<html> 
<head> 

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link rel="stylesheet" href="style2.css"> 

    <title>Update menu</title> 

</head> 

<body> 
<h1>Update the menu!</h1>
<form method="POST" action="update.php">
<?php
$query="SELECT * from menu WHERE Item_id='$Item_id'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
    $Item_id=$row[0];
    $Item_name=$row[1];
    $Price=$row[3];
    $Description=$row[2];



}

?>
<label style="color:white;">
<strong>Item name: </strong><br />
<input type="text" name="name" size="30" value="<?php echo $Item_name;?>"></label> <br />
<label style="color:white;">
<strong>Price: </strong><br />
<input type="text" name="Price" size="5" value="<?php echo $Price;?>"></label><br />

<label style="color:white;">
<strong>Item description: </strong><br />
<input name="Description" size="40" value="<?php echo $Description;?>"></label><br />



<input type="hidden" name="Item_id" size="5" value="<?php echo $Item_id;?>">

<input type="submit" value="Update" style="color:black; background-color:#f2f2f2;">
</form>


</body>
 </html>

和update.php

<!DOCTYPE html>
<html>
<head>
<title>Update menu</title>
</head>
<body>
<?php
$conn=mysql_connect("localhost","root","");
$db=mysql_select_db("project",$conn);
$query="UPDATE menu SET Item_name='".$_POST['Item_name']."',Description='".$_POST['Description']."',Price='".$_POST['Price']."'WHERE Item_id='$id'";
//echo query
$result=mysql_query($query,$conn);
mysql_close($conn);
header("Location:http://localhost/project/aindex.php");
exit();


?>


</body>
</html>

输出: here is the error!!

1 个答案:

答案 0 :(得分:0)

在while循环之前声明错误显示的变量。