1
私はこのコードに問題がありました!!私はそれを書いたが、実行時には、それは未定義の変数です!私はどこにエラーがあるか分からなかった。私を助けてください。 私の知る限り、connection.phpにはすでに定義されています。phpとmysqlのデータを更新
<?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>
出力updateform.php :
here is the error!!
1.エラーをそのまま記入してください。 2. PDOを学んでください:) – AshMenhennett
@AshMenhennett私はエラーを投稿します。これは、単純なMySQLで私と一緒に働くことです。 –
エラーで示された変数をwhileループの前に宣言します。初期値を設定すると、 '' 'null'''は大丈夫でしょう。 – AshMenhennett