...

View Full Version : not able to save data into table



naveendk.55
09-28-2011, 02:26 PM
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

$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

sunfighter
09-28-2011, 04:19 PM
Your missing a comma after "review_date" in this line:
$query = "INSERT INTO test (e_name, agent_name, userid, processing_date, review_date " .

naveendk.55
09-28-2011, 05:53 PM
YES, that resolved the issue.

naveendk.55
09-29-2011, 03:33 PM
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

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

Wanna
09-29-2011, 03:45 PM
You have a , at the last value. If you do this SQL expects there is a another coulmn you want to fill.

naveendk.55
09-29-2011, 03:50 PM
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"

Wanna
09-29-2011, 05:58 PM
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.

naveendk.55
09-29-2011, 06:42 PM
I'm aware that using any ' or " will cause this. So I tested with single words without any quotes. But no success.

Old Pedant
09-29-2011, 09:55 PM
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.

naveendk.55
09-30-2011, 01:47 PM
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.

coin
09-30-2011, 09:10 PM
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.


$query = ""; //your query
$result = mysql_query($query) or die(mysql_error().' - '.$query);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum