2015-07-11 120 views
1

错误:MySQL的语法错误#1064 - 插入

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数据库表:

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 
+0

1064:你的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以便在'(id,name,url,content,category)附近使用正确的语法INTO articles VALUES(null,'Names','names','text'in line 1 – Jacob

+0

字段列表出现在表名后面。参见[here](http://www.w3schools.com/sql/sql_insert.asp) –

+0

如果这些变量来自用户输入,请确保您正在转义它们,或者更好地使用准备好的语句。 – chris85

回答

2

你得到了查询上半年倒退。首先你要说明要插入什么表格,然后列出要接收值的字段。

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

非常感谢你 – Jacob

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')"; 
+0

非常感谢你 – Jacob