Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP, MySQL error: Column count doesn't match value count at row 1

Tags:

php

mysql

I'm getting this error:

Column count doesn't match value count at row 1

From the following code:

$name = $_GET['name']; $description = $_GET['description']; $shortDescription = $_GET['shortDescription']; $ingredients = $_GET['ingredients']; $method = $_GET['method']; //$image = $_GET['image']; $username = $_GET['username']; $length = $_GET['length']; $dateAdded = uk_date(); $conn = mysql_connect('localhost', 'dbname', 'pass'); mysql_select_db('dbname'); $query = sprintf("INSERT INTO dbname (id, Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",     mysql_real_escape_string($name),     mysql_real_escape_string($description),     mysql_real_escape_string($shortDescription),     mysql_real_escape_string($ingredients),     //mysql_real_escape_string($image),     mysql_real_escape_string($length),     mysql_real_escape_string($dateAdded),     mysql_real_escape_string($username));      $result = mysql_query($query) or die(mysql_error()); 

What does the error mean?

like image 918
max_ Avatar asked May 09 '11 02:05

max_


People also ask

How do you resolve a column count that doesn't match value count at row 1?

To resolve this “Column count doesn't match value count at row 1” error, you have to ensure that the columns in the table or your INSERT statement match the values you are inserting. The best way to do this is to specify the columns you want in your INSERT statement and ensure the VALUES clause matches the column list.

How do I fix error 1136 in MySQL?

To fix this issue, make sure you're inserting the correct number of columns into the table. Alternatively, you can name the columns in your INSERT statement so that MySQL knows which columns your data needs to be inserted into.

How do I count values in a column in MySQL?

MySQL COUNT(*) with GROUP BY Clause It returns the total number of values residing in each group. For instance, if you want to check each user's number separately, you have to define the column 'User' with the GROUP BY clause while counting records for each user with COUNT(*). >> SELECT User, COUNT(*) FROM data.

How do I add a column to a table in MySQL?

The syntax to add a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name ADD new_column_name column_definition [ FIRST | AFTER column_name ]; table_name.


2 Answers

You have 9 fields listed, but only 8 values. Try adding the method.

like image 107
Ignacio Vazquez-Abrams Avatar answered Sep 28 '22 00:09

Ignacio Vazquez-Abrams


The number of column parameters in your insert query is 9, but you've only provided 8 values.

INSERT INTO dbname (id, Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s') 

The query should omit the "id" parameter, because it is auto-generated (or should be anyway):

INSERT INTO dbname (Name, Description, shortDescription, Ingredients, Method, Length, dateAdded, Username) VALUES ('', '%s', '%s', '%s', '%s', '%s', '%s', '%s') 
like image 24
Tharsan Avatar answered Sep 28 '22 01:09

Tharsan