Reputation: 33
Error:
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 Code:
$sql = "INSERT (id, name, url, content, category) INTO articles
VALUES (null, '$name', '$url', '$content', '$category')";
$insert = MySQL_Query($sql);
and MySQL database 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
Upvotes: 1
Views: 3381
Reputation: 219794
You got the first half of the query backwards. First you say what table to insert into, then you list the fields to receive values.
$sql = "INSERT INTO articles (id, name, url, content, category)
VALUES (null, '$name', '$url', '$content', '$category')";
Upvotes: 2
Reputation: 310993
Your syntax is incorrect - it should be insert into table_name (column list) values (value list)
. So, in your case:
$sql = "INSERT INTO articles (id, name, url, content, category)
VALUES (null, '$name', '$url', '$content', '$category')";
Upvotes: 1