Loading ...
Sorry, an error occurred while loading the content.

Need help with mysql error

Expand Messages
  • Gu®u
    Hi All, I am working a a project in which there is a table with some variables. I have a form with which I pull the filled data by user and want to put into
    Message 1 of 2 , Jun 7, 2013
    • 0 Attachment
      Hi All,

      I am working a a project in which there is a table with some variables. I have a form with which I pull the filled data by user and want to put into mysql dtabase. Below is my query.

      $sql="INSERT INTO recipt (date, pt_name, age, od_sph, od_cyl, od_axis, os_sph, os_cyl, os_axis, add, d_sph, od_d, od_n, od1, os1)
      VALUES
      ('$_POST[date]','$_POST[pt_name]','$_POST[age]','$_POST[od_sph]','$_POST[od_cyl]','$_POST[od_axis]','$_POST[os_sph]','$_POST[os_cyl]','$_POST[os_axis]','$_POST[add]','$_POST[d_sph]','$_POST[od_d]','$_POST[od_n]','$_POST[od1]','$_POST[os1]')";

      However I am getting an error saying:

      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 'add, d_sph, od_d, od_n, od1, os1) VALUES ('12-12-2013','guru prasad','23','12'' at line 1

      I have tried gooling it but no luck. Please help me with this error.

      Thank you in advance.

      --
      Best,
      Gu®u
      CEO & Founder at,
      www.myshopads.com
    • Amin
      add is a reserve keyword of mysql. Thats why when you use add as a field name, mysql get the add word as their keyword. you can avoid this bug in two ways: 1.
      Message 2 of 2 , Jun 21, 2013
      • 0 Attachment
        add is a reserve keyword of mysql. Thats why when you use add as a field name, mysql get the add word as their keyword.

        you can avoid this bug in two ways:

        1. use backticks (``) to write your fields & tables in the query.

        2. rename the fields name that are same of mysql reserve keyword.



        wish my solution work for you.


        Md. Shah Alom Hossen Amin
        Programmer (PHP, J2EE),
        +88 01935946949
        http://dealsinbd.com/
        http://tutpub.com/
      Your message has been successfully submitted and would be delivered to recipients shortly.