Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Error in inserting query in MySQl

    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

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,859
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •