mysql update语句给我一个错误

时间:2012-04-15 10:45:32

标签: php mysql

我正在尝试一次更新多个列:

  $query="UPDATE search_page
     SET search_page_description='".$search_page_description."',
     SET title='".$title."',
     SET h1='".$h1."',
     SET meta_description='".$metadata."'
     WHERE features_id=".$id;
     $result_update_query=databaseConn :: dbDelta($query);

我明白了:

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 'SET title='fasdf', SET h1='fasdfas', SET meta_description='fas' at line 3

我的代码在哪里出错?

3 个答案:

答案 0 :(得分:5)

您只需要一个SET关键字

 $query="UPDATE search_page
     SET search_page_description='".$search_page_description."',
     title='".$title."',
     h1='".$h1."',
     meta_description='".$metadata."'
     WHERE features_id=".$id;
     $result_update_query=databaseConn :: dbDelta($query);

参见参考:http://dev.mysql.com/doc/refman/5.5/en/update.html

答案 1 :(得分:1)

错误说明第3行:

  

“SET title ='”。$ title。“',”

问题是此行包含不期望的“SET”关键字。

 $query="UPDATE search_page
 SET search_page_description='".$search_page_description."',
 title='".$title."',
 h1='".$h1."',
 meta_description='".$metadata."'
 WHERE features_id=".$id;
 $result_update_query=databaseConn :: dbDelta($query);

请参阅MySQL Reference或尝试SQL UPDATE Statement

答案 2 :(得分:1)

试试这些:

>   $query="UPDATE search_page
>      SET search_page_description='".$search_page_description."',
>      title='".$title."',
>      h1='".$h1."',
>      meta_description='".$metadata."'
>      WHERE features_id=".$id;
>      $result_update_query=databaseConn :: dbDelta($query);