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 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    99
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question not able to save data into table

    I'm trying to send the details to database and getting the below error.

    Notice: Use of undefined constant e_name - assumed 'e_name' in C:\wamp\www\ggg\testing.php on line 6



    PHP Code:
    <?php

    $e_name 
    $_POST['e_name'];                      /* data type = text in the table. Also there is one more attribute in the table caled ID with autoincrement*/
    $aname $_POST['aname'];                      /* data type =  text */
    $sapid $_POST['sapid'];                      /* data type =  text */
    $processing_date $_POST['processing_date'];     /* data type =  date */
    $review_date $_POST['review_date'];         /* data type =  date */
    $contact $_POST['contact_ID'];                /* data type = text */
    $audit_type $_POST['audit_type'];                   /* data type = text */
    $case_no $_POST['case_no'];                   /* data type = integer */

    $query "INSERT INTO test (e_name, agent_name, userid, processing_date, review_date " .
            
    " contact_ID, audit_type, case_no) " .
            
    " VALUES " .
            
    " ('{$e_name}', '{$aname}', '{$sapid}', '{$processing_date}', '{$review_date}', '{$contact}', '{$audit_type}', " .
            
    " {$case_no} )";

    $result mysql_query($query) or die("Error while inserting data"mysql_error());

    mysql_close($connection);

    ?>
    Then below I got this error:

    Error while inserting dataYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'contact_ID, audit_type, case_no) VALUES ('', '', '', '', '', '', '', )' at line 1
    Last edited by naveendk.55; 09-28-2011 at 01:59 PM. Reason: edited the code

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,771
    Thanks
    23
    Thanked 550 Times in 549 Posts
    Your missing a comma after "review_date" in this line:
    $query = "INSERT INTO test (e_name, agent_name, userid, processing_date, review_date " .

  • Users who have thanked sunfighter for this post:

    naveendk.55 (09-28-2011)

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    99
    Thanks
    7
    Thanked 0 Times in 0 Posts
    YES, that resolved the issue.

  • #4
    New Coder
    Join Date
    Aug 2011
    Posts
    99
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question same issue again

    Hi, now again I increased the table fields and getting the error beow.

    "Error while inserting dataYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('', 'kumar', '6541111', 01/01/2011, '01/01/2011',' at line 7".


    PHP Code:

    <?php

    $e_name 
    $_POST['evaluator_name'];                      /* data type = text in the table. Also there is one more attribute in the table caled ID with autoincrement */
    $aname $_POST['aname'];                      /* data type =  text */
    $sapid $_POST['sapid'];                      /* data type =  text */
    $processing_date $_POST['processing_date'];     /* data type =  date */
    $review_date $_POST['review_date'];         /* data type =  date */
    $contact $_POST['contact_ID'];                /* data type = text */
    $audit_type $_POST['audit_type'];                   /* data type = text */
    $case_no $_POST['case_no'];                   /* data type = integer */
    $product_name1 $_POST['product_name1'];
    $product_name2 $_POST['product_name2'];
    $product_name3 $_POST['product_name3'];
    $product_name4 $_POST['product_name4'];
    $product_name5 $_POST['product_name5'];
    $product_name6 $_POST['product_name6'];
    $product_name7 $_POST['product_name7'];
    $product_name8 $_POST['product_name8'];
    $product_name9 $_POST['product_name9'];
    $product_name10 $_POST['product_name10'];
    $product_name11 $_POST['product_name11'];
    $product_name12 $_POST['product_name12'];
    $product_name13 $_POST['product_name13'];
    $product_name14 $_POST['product_name14'];
    $product_name16 $_POST['product_name16'];
    $Para_A_A1_score $_POST['Para_A_A1_score'];
    $Para_A_A2_score $_POST['Para_A_A2_score'];
    $Para_A_A3_score $_POST['Para_A_A3_score'];
    $Para_A_A4_score $_POST['Para_A_A4_score'];
    $Para_A_A5_score $_POST['Para_A_A5_score'];
    $Para_A_A6_score $_POST['Para_A_A6_score'];
    $Para_A_A1_Comment $_POST['Para_A_A1_Comment'];
    $Para_A_A2_Comment $_POST['Para_A_A2_Comment'];
    $Para_A_A3_Comment $_POST['Para_A_A3_Comment'];
    $Para_A_A4_Comment $_POST['Para_A_A4_Comment'];
    $Para_A_A5_Comment $_POST['Para_A_A5_Comment'];
    $Para_A_A6_Comment $_POST['Para_A_A6_Comment'];

    $query "INSERT INTO test (e_name, agent_name, userid, processing_date, review_date, 
             contact_ID, audit_type, case_no, product_name, duration, errors, 
            mark_parameter_A, mark_parameter_B, mark_parameter_C, mark_parameter_D, mark_parameter_E, 
           mark_parameter_F, mark_parameter_G, mark_parameter_H, mark_parameter_I, mark_parameter_J, 
             Total_Possible, Score, Para_A_A1, Para_A_A2, Para_A_A3, Para_A_A4, Para_A_A5, Para_A_A6, 
             Para_A_A1_Comment, Para_A_A2_Comment, Para_A_A3_Comment, Para_A_A4_Comment, Para_A_A5_Comment, 
           Para_A_A6_Comment) 
             VALUES 
            ('{$evaluator_name}', '{$aname}', '{$sapid}', {$processing_date}, {$review_date}, '{$contact_ID}', 
            '{$audit_type}', 
             {$case_no}, '{$product_name1}', '{$product_name2}', {$product_name3}, {$product_name4}, {$product_name5}, 
              {$product_name6}, {$product_name7}, {$product_name8}, {$product_name9}, {$product_name10}, {$product_name11}, 
              {$product_name12}, {$product_name13}, {$product_name14}, {$product_name16}, 
              {$Para_A_A1_score}, {$Para_A_A2_score}, {$Para_A_A3_score}, {$Para_A_A4_score}, {$Para_A_A5_score}, 
              {$Para_A_A6_score},   
              '{$Para_A_A1_Comment}', '{$Para_A_A2_Comment}', '{$Para_A_A3_Comment}', '{$Para_A_A4_Comment}', 
              '{$Para_A_A5_Comment}', '{$Para_A_A6_Comment}'  )"
    ;

    $result mysql_query($query) or die("Error while inserting data" mysql_error());

    mysql_close($connection);
    ?>
    Last edited by naveendk.55; 09-29-2011 at 03:21 PM. Reason: changes

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    You have a , at the last value. If you do this SQL expects there is a another coulmn you want to fill.

  • #6
    New Coder
    Join Date
    Aug 2011
    Posts
    99
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question

    now, the error is as below.

    "Error while inserting dataYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '', '', '', '', '', '' )' at line 15"

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Try to mysql_real_escape_string all the variables before you insert them in the sql statement.
    From what i can see you fill the field: $_POST['Para_A_A1_Comment'];
    with a '.

    If you do it on the way you do, this can be done.

  • #8
    New Coder
    Join Date
    Aug 2011
    Posts
    99
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I'm aware that using any ' or " will cause this. So I tested with single words without any quotes. But no success.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Since we don't know the data types of all your fields, we can't debug this.

    Possibly you are trying to put a text value '{$name}' into an integer field, for example.

    The best thing to do is echo the SQL to the screen (e.g., echo "<hr>" . $query . "<hr>";) and then use a DB tool--*NOT* php--to execute the query. Most tools will give you better information.

    If not, then show us the result of the echo.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    New Coder
    Join Date
    Aug 2011
    Posts
    99
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question

    As for as data type is concerned, I checked again and found that its is text.

    I did an incremental testing ( adding one filed and checking if it works or not) and found that it works upto the $Para_A_A6_score. Once I add the $Para_A_A1_Comment variable that is text, it started giving errors.

  • #11
    New Coder
    Join Date
    Sep 2011
    Posts
    24
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Also, you are trying to insert {$evaluator_name} but defined $_POST['evaluator_name'] as $e_name at the top.

    Also, like Old Pedant said, it's always good to put your query into a variable so that you can echo it with your error.
    PHP Code:
    $query ""//your query
    $result mysql_query($query) or die(mysql_error().' - '.$query); 


  •  

    Posting Permissions

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