Column count doesn’t match value count at row 1
This error was making me crazy with my PHP / mySQL project ! No matter what I seemed to do, the error was the same: Column count doesn't match value count at row 1
I was trying to insert some values into a mySQL database, and I was first have problems with the following code:
$mysql_query = "INSERT INTO reports VALUES ('$data1', '$data2', '$data3', '$data4', '$data6', '$user_ID', '')";
After a lot of headaches, I realized that my database had more rows then the query I was using. I forgot to list $data5 in the query. (I've changed the variable names to more clearly illustrate my mistake)
But then I had the following query string and was STILL getting the same error:
$mysql_query = "INSERT INTO reports VALUES ('$data1', '$data2', '$data3', '$data4', '$data5' '$data6', '$user_ID', '')";
I kept banging my head against the fridge when I realized that my query string was missing a comma between $data5 and $data6. Once I put the comma in, there were no worries.
This problem was especially frustrating, because the database wouldn't insert the data and there was no warning message. To see a mySQL PHP error message, you need to explicitly ask for one by including the following:
echo "Error message = ".mysql_error();
Having added the above code, I could finally start to identify why the INSERT command wasn't working. What a pain. Of course, this isn't the preferred method to insert data anyway into a mySQL database, but maybe understanding the error message will help you.
Aucun trackbacks pour l'instant