PHP, MySQL Error: Column Count Doesn't Match Value Count At Row 1

PHP-ERROR: Column count doesn't match value count at row 1

use this structure on insert:

$strQuery = "INSERT INTO posts (id, title, category, tags, details, added_by, user_to, date_added, user_closed, deleted, likes) VALUES('','$title', '$category', '$tags' '$details', '$added_by', '$user_to', '$date_added', 'no', 'no', 0)";

$query = mysqli_query($this->con, $strQuery);

if ID is Auto-incrment key you can make the insert without it... like this (10 Column and Values):

$strQuery = "INSERT INTO posts (title, category, tags, details, added_by, user_to, date_added, user_closed, deleted, likes) VALUES('$title', '$category', '$tags' '$details', '$added_by', '$user_to', '$date_added', 'no', 'no', 0)";

$query = mysqli_query($this->con, $strQuery);

PHP ~ Column count doesn't match value count at row 1

The issue is because the number you're passing in has a comma in it and isn't a string. You need to either pass in "40,000.00" or 40000.00. MySQL is interpreting it as two values: 40 and 000.00.

Using prepared statements will alleviate this (and your security issue) because binding will interpret 40,000.00 as a string. A very basic example to get you started would be:

$sql = "INSERT INTO provide_help (amount) VALUES (?)";
$stmt = $mysqli->prepare($sql);

/*
- the "s" below means string
- NOTE you should still validate the $_POST value,
don't just accept whatever is sent through your form -
make sure it matches the format you're expecting at least
or you'll have data validation issues later on
*/
$stmt->bindParam("s", $field1amount);
$stmt->execute($fieldAmount1);
$result = $res->fetch_assoc();

Column count doesn't match value count at row 1 while updating a record

It could be of few things

  1. The value that you are updating the cell to exceeds the column length
  2. There is a trigger that needs to be changed/removed.

Hope this helps.



Related Topics



Leave a reply



Submit