0

hiiii friends,

i have a table messages whose columns are

id(primary key,auto increment) from to sub body

now when i am trying to insert in the table with the following syntax

insert into messages values(2,'$from','$to','$sub','$body')
it is working fine.

but since the id is in auto increment mode i am using the following syntax

insert into messages(from,to,subject,body) values('$from','$to','$sub','$body')

i am getting an error that there is a sql syntax error plz chek the manual for correct syntax.


can u help me in solving this

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ThinkFree
0

Try:

insert into messages (`from`,`to`,`subject`,`body`) values ('$from','$to','$sub','$body')

If you still have errors, than there could be unescaped quotes in the subject or body.

0

^Will you please tell what is the need of using back-ticks? I always use insert statements without these, and haven't encountered any problem as yet.

1

"from" is also a reserved word (SELECT * FROM). The backticks are used to specify explicitly it is a column name.

0

"from" is also a reserved word (SELECT * FROM). The backticks are used to specify explicitly it is a column name.

Thanks. In fact, MySQL isn't allowing creation of table with field FROM.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.