Unable to insert record (what's wrong with php code)

Status
Not open for further replies.

Sridhar_Rao

In the zone
Hi guys, help me troubleshoot this simple problem. I am not able to insert a record into a table. here is the code:

PHP:
    $sql = "insert into mytable(state,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14,q15) VALUES($a16,$a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,$a10,$a11,$a12,$a13,$a14,$a15)"; 
    if (mysql_query($sql)) {
        echo('<p align="Center">Your response has been successfully registered.</p>');
        //from here begins coding to analyze and display poll results
    } else {
        echo('<p align="Center">There was an error in inserting record.</p>');
    }
I have enabled error reporting using error_reporting(E_ALL);
but no error is being displayed except for my own custom error (There was an error in inserting record). How can I get it to display the error code too?

OK, I solved this problem by adding a piece of code:
PHP:
echo('<p align="Center">There was an error in registering your poll response.'.mysql_error().'</p>');
The value of $a1 is B. The error that is displayed now is Unknown column 'B' in 'field list'. What does this mean? Can you spot the error? I even tried echoing the all the variables $a1 to $a16 and they all get displayed correctly.
 
Last edited:

victor_rambo

हॉर्न ओके प्लीज़
PHP:
VALUES('$a16','$a1','$a2',......,'$a15')
Unless the values are an integer, you should put them in quotes.
 
Status
Not open for further replies.
Top Bottom