Jacob
Jacob

Reputation: 33

MySQL syntax error #1064 - INSERT

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

Answers (2)

John Conde
John Conde

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

Mureinik
Mureinik

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

Related Questions