954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem in inserting query in database

Hi everyone,

I am inserting value in a table in a database through query but it is giving some error as like this :-

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', '21', '2009')' at line 1


and the code for inserting these value is as i writing this code:-


$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());


But i am receiving this error. I am unable to insert records in database. Please help me. How i can sort out this problem.
Thanks,
Gagan

gagan22
Junior Poster
131 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

leave is a mysql statement. try putting backticks around it.

$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());
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You