我正在使用html表单使用php更新mysql数据库。它不断给出这个错误
“您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以便在第1行'WHERE id ='1'附近使用正确的语法”
这是y php代码:
<?php
$host="localhost"; // Host name
$username="name"; // Mysql username
$password="pass"; // Mysql password
$db_name="dbname"; // Database name
$tbl_name="tblname"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$id = '1';
$name = $_POST['name'];
$info = $_POST['minfo'];
$poster = $_POST['poster'];
$mtrailer = $_POST['mtrailer'];
// update data in mysql database
$sql = "UPDATE movies SET name='$name', info='$info', poster='$poster', mtrailer='$mtrailer', WHERE id = '$id'";
$result = mysql_query($sql) or die(mysql_error());;
?>
这是我正在使用的html表单:
<FORM action="update.php" method="post">
<INPUT type="text" name="name" value="<?php echo $name; ?>" id="name" placeholder="Name" required=""><BR>
<INPUT type="text" name="minfo" value="<?php echo $info; ?>" id="minfo" placeholder="Description" required=""><BR>
<INPUT type="text" name="poster" value="<?php echo $poster; ?>" id="poster" placeholder="Poster URL" required=""><BR>
<INPUT type="text" name="mtrailer" value="<?php echo $trailer; ?>" id="mtrailer" placeholder="Trailer URL" required=""><BR>
<INPUT type="submit" value="update">
</FORM>
答案 0 :(得分:1)
您在WHERE