MySQL 语法错误 #1064 - 插入

MySQL syntax error #1064 - INSERT

错误:

1064: 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 '(id, name, url, content, category) INTO articles VALUES (null, 'Names', 'names', 'text' at line 1

PHP代码:

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

和MySQL数据库table:

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

你把查询的前半部分倒过来了。首先你说要插入什么table,然后你列出要接收值的字段。

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

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

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