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

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.

^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.

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

"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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.