0

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

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

4 回答 4

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')
于 2013-11-06T16:38:11.917 回答
1

DESC是一个保留关键字,您不能将其作为一列使用反引号运算符将其包围。

这里..

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

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

于 2013-11-06T16:37:54.783 回答
1

在周围添加 Backtic,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')
于 2013-11-06T16:39:34.897 回答
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')";
于 2013-11-06T16:38:17.553 回答