Search code examples
phpmysqlinsert

SQL syntax error when I use column name "from"


I have problem with query, anybody see something bad?

INSERT INTO messages (subject, from, recipient, text, time)
VALUES
('Welcome in King of the States!','The Game','$username','Hello $username, THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')

Error from sql:

#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 'from, recipient, text, time) VALUES ('Welcome in King of the States!','The Gam' at line 1

Solution

  • from is a mysql reserved word. try placing from in backtick

    Like below:

    `from`