Search code examples
phpmysqlsyntaxsyntax-errormysql-error-1064

MySQL error - "You have an error in your SQL syntax"


The error message I got:

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 ''word','group','selfnote') VALUES ('item','a','note to self')' at line 1

The PHP code is:

$toq="INSERT INTO articles ('word','group','selfnote') 
VALUES ('$ttle','$wrdr','$snote')";

I was trying to find solutins, but they didn't seem to work as echoing gives:

INSERT INTO articles ('word','group','selfnote') 
VALUES ('item','a','note to self')

which seems nice to me. What is the problem?


Solution

  • Use backticks ` instead of quotes ' to escape names. Quotes are string delimiters.

    $toq="INSERT INTO articles (`word`,`group`, `selfnote`) VALUES ('$ttle','$wrdr','$snote')";