1
INSERT INTO mo_received 
(appid, msg, to, from, operator, keyword, smsid, udh, response, created) 
VALUES 
('13846', 'HELLO', '123456789', '987654321', 
'SKTELECOM', 'Cheese', 'MESSAGE', 'UDHSTUFF', '', NOW());

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 'to, from, operator, keyword, smsid, udh, response, created) VALUES ('13846', 'HE' at line 1

That's the error I get.

Strange thing is that if I remove the "to" and "from" fields and values the insert works ok. But I don't see anything wrong with those fields.

Any ideas?

2
  • 1
    I think to and from are reserved keywords in my sql, use backticks: (appid, msg, to, from, operator, keyword, smsid, udh, response, created) Commented Apr 25, 2012 at 2:27
  • Suggest you change the name of the field "from" it's a reserved word in SQL. It's just going to cause you trouble. I'd call it "msgfrom" or similar. Commented Apr 25, 2012 at 2:29

2 Answers 2

2

"to" and "from" are not recommended for column name. It's reserved.
http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

If you use reserved column name, surround with reverse single quote.

INSERT INTO mo_received (appid, msg, `to`, `from`, operator, keyword, smsid, udh, response, created) 
Sign up to request clarification or add additional context in comments.

Comments

1

See http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

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.