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
- The value that you are updating the cell to exceeds the column length
- There is a trigger that needs to be changed/removed.
Hope this helps.
Related Topics
Is There Any Particular Difference Between Intval and Casting to Int - '(Int) X'
How to Enable Curl in Wamp Server
How to Implement a Callback in PHP
How to Get the Current Page'S Full Url on a Windows/Iis Server
Submit an HTML Form With Empty Checkboxes
PHP - Merging Two Arrays into One Array (Also Remove Duplicates)
How to Change Maximum Number of Post Variable in PHP
Laravel - Eloquent or Fluent Random Row
When to Use Strtr VS Str_Replace
How to Delete Element With Domdocument
Best Way to Completely Destroy a Session - Even If the Browser Is Not Closed
How to Access PHP With the Command Line on Windows
How to Execute PHP That Is Stored in a MySQL Database
A Formula to Find Prime Numbers in a Loop
Variable-Length Lookbehind-Assertion Alternatives For Regular Expressions