dqcuq4138 2013-11-17 20:08
浏览 36
已采纳

MySQL语法错误(试图更新MySQL数据库)[关闭]

I'm using an html form to update mysql database using php. and it keeps giving this error

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = '1'' at line 1"

here is y php code:

<?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());;
?> 

and this is the html form that I'm using:

<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条回答 默认 最新

  • duan5362 2013-11-17 20:10
    关注

    You have a comma before the WHERE

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maixpy训练模型,模型训练好了以后,开发板通电会报错,不知道是什么问题
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容