Home » Php » php – MySQL column count doesn't match value count at row 1

php – MySQL column count doesn't match value count at row 1

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’m trying to insert data into a MySQL table using PHP, but getting the error

Column count doesn’t match value count at row 1

mysql_query("INSERT INTO file (id, filename, extention, filelink, filesize, filepass) VALUES('{$random}', '{$filename}', '{$extension}', '{$filelink}', '{$filesize}' '{$filepass}') ") or die(mysql_error());
How to&Answers:
mysql_query("INSERT INTO file (id, filename, extention, filelink, filesize, filepass) VALUES('{$random}', '{$filename}', '{$extension}', '{$filelink}', '{$filesize}' '{$filepass}') ") or die(mysql_error());

You should add the missing comma after {$filesize}:

mysql_query("INSERT INTO file (id, filename, extention, filelink, filesize, filepass) VALUES('{$random}', '{$filename}', '{$extension}', '{$filelink}', '{$filesize}', '{$filepass}') ") or die(mysql_error());

Answer:

'{$filesize}' '{$filepass}' is being considered as a single value since you’re missing the comma. Your query would look like:

INSERT INTO file (id, filename, extention, filelink, filesize, filepass)
VALUES ( '{$random}',
         '{$filename}',
         '{$extension}',
         '{$filelink}',
         '{$filesize}' '{$filepass}')

There. You have 6 columns and 5 values. The column count doesn’t match the value count and hence MySQL throws an error message.