MySQL语法错误(尝试更新MySQL数据库)

时间:2013-11-17 20:08:25

标签: php mysql sql forms

我正在使用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>

1 个答案:

答案 0 :(得分:1)

您在WHERE

之前有逗号