Search code examples
phpmysqlsqlsyntax-errormysql-error-1064

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

Solution

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