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?
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.
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.
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.
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.
You have 9 fields listed, but only 8 values. Try adding the method.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With