SQL语法错误(插入)

时间:2013-11-06 16:36:44

标签: php sql

好吧,我收到了这个错误:

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 'desc,fb_title,fb_pic,fb_url,fb_desc) VALUES('', '', '', '', '', '', '', ''' at line 1

以下代码:

$sql="INSERT INTO page(title,css,favicon,charset,keywords,author,desc,fb_title,fb_pic,fb_url,fb_desc)
VALUES('$title', '$css', '$favicon', '$charset', '$keywords', '$author', '$desc', '$fb_title', '$fb_pic', '$fb_url', '$fb_desc')";

一切看起来都很好......怎么了?

4 个答案:

答案 0 :(得分:2)

DESC是保留关键字。你应该把它作为`DESC`来逃避它。

INSERT INTO page(title,css,favicon,charset,keywords,author,`desc`,fb_title,fb_pic,fb_url,fb_desc)
  VALUES('$title', '$css', '$favicon', '$charset', '$keywords', '$author', '$desc', '$fb_title', '$fb_pic', '$fb_url', '$fb_desc')

答案 1 :(得分:1)

DESC 是一个保留关键字,您不能使用反引号操作符将其作为其他方式包围它。

下面..

$sql="INSERT INTO page(title,css,favicon,charset,keywords,author,desc,fb_t
                                                     ------------^

免责声明:不推荐使用mysql_ *函数,因为它们已被弃用。改为使用MySQLi或PDO。

答案 2 :(得分:1)

desc附近添加反引号,因为它是一个保留字

INSERT INTO page(title,css,favicon,charset,keywords,author,`desc`,fb_title,fb_pic,fb_url,fb_desc)
VALUES('$title', '$css', '$favicon', '$charset', '$keywords', '$author', '$desc', '$fb_title', '$fb_pic', '$fb_url', '$fb_desc')

答案 3 :(得分:0)

desc是mysql的保留关键字

$sql="INSERT INTO page(`title`, `css`, `favicon`, `charset`, `keywords`, `author`,`desc`,`fb_title`,`fb_pic`,`fb_url`,`fb_desc`)
VALUES('$title', '$css', '$favicon', '$charset', '$keywords', '$author', '$desc', '$fb_title', '$fb_pic', '$fb_url', '$fb_desc')";