PHP, MySQL error: the number of columns does not match the number of values ​​in row 1

I get 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?

+44
php mysql
May 09 '11 at 2:25
source share
3 answers

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

+80
May 09 '11 at 2:31
source share

The number of column parameters in your insert request is 9, but you specified only 8 values.

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

The request should omit the id parameter, as 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') 

Good luck

+13
May 9 '11 at 2:34
source share

Your query has 8 or possibly even 9 variables, i.e. Name, description, etc. But the values, these things ---> '', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" , total 7, the number of variables should be the same as the values.

I had the same problem, but I figured it out. Hope it works for you too.

+6
01 Oct
source share



All Articles