1

I had a problem with this code!! I wrote it but in the run its tell that is undefined variable !! I did not know where is the error. Please help me. for my knowledge it is already defined in the 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>

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

the output: here is the error!!

Sarah AH
  • 69
  • 1
  • 9

1 Answers1

0

Declare the variables shown in error before the while loop.

AshMenhennett
  • 1,095
  • 4
  • 14
  • 25