...

View Full Version : Error in inserting query in MySQl



gagan
03-26-2009, 01:02 PM
Hi everyone,

I am writing insert query in php file but it is giving error. I explain my problem.
I am wriitng such code in a php file

$sqlquery = "insert into leave (session_id,empid,leave,year) values('$_SESSION[id]', '$_SESSION[empid]', '$_POST[leavenum]', '$_POST[year]')";
$res = mysql_query($sqlquery,$link) or die('Error: ' . mysql_error());

after that problem is it is showing this error in this page

Error: 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 'leave (session_id,empid,leave,year) values('20202', 'DTL0009', '12', '2010')' at line 1

How i can solve this problem . Please help me . It is very urgent for me.

Thanks
gagan

abduraooft
03-26-2009, 01:14 PM
leave is mysql reserved word (http://dev.mysql.com/doc/refman/5.0/en/leave-statement.html) (as per the manual), so you can't use it in your query as the name of your table or field. You can avoid the errors by enclosing the name in quotes, but it's not a good practice. So I'd recommend to change the name if possible.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum