1

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
3
  • 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 Commented Jul 11, 2015 at 14:30
  • Field list comes after table name.See here. Commented Jul 11, 2015 at 14:31
  • If those variables come from user input make sure you are escaping them, or better use prepared statements. Commented Jul 11, 2015 at 14:36

2 Answers 2

2

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')";
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.