Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
03-26-2009, 01:02 PM #1
- Join Date
- Feb 2009
- Thanked 0 Times in 0 Posts
Error in inserting query in MySQl
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.
03-26-2009, 01:14 PM #2
- Join Date
- Mar 2007
- Thanked 2,232 Times in 2,219 Posts
leave is mysql reserved word (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.