MySQL语法错误#1064 - INSERT

时间:2015-07-11 14:28:35

标签: php mysql sql syntax-error mysql-error-1064

错误:

  

1064:您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'(id,name,url,content,category)附近使用正确的语法INTO文章VALUES(null,'Names','names','text'在第1行< / p>

PHP代码:

$sql = "INSERT (id, name, url, content, category) INTO articles
VALUES (null, '$name', '$url', '$content', '$category')";
$insert = MySQL_Query($sql);

和MySQL数据库表:

id PRIMARY  tinyint(20)     UNSIGNED   AUTO_INCREMENT 
name        varchar(255)    utf8_general_ci
url         varchar(255)    utf8_general_ci
content     longtext        utf8_general_ci
category    varchar(255)    utf8_general_ci

2 个答案:

答案 0 :(得分:2)

您向后查询了前半部分。首先你要说明要插入哪个表,然后列出要接收值的字段。

$sql = "INSERT INTO articles (id, name, url, content, category)
VALUES (null, '$name', '$url', '$content', '$category')";

答案 1 :(得分:1)

您的语法不正确 - 它应该是insert into table_name (column list) values (value list)。所以,在你的情况下:

$sql = "INSERT INTO articles (id, name, url, content, category)
VALUES (null, '$name', '$url', '$content', '$category')";