Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-24-2010, 06:09 AM   #1
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
DBD::mysql::st execute failed: Column count doesn't match value count at row 1

I have the following perl/DBI script:

use DBI;

my ($db, $user, $pw) = ('dbname', '****', '***********');

my $dbh = DBI->connect("DBI:mysql:$db",$user,$pw) or die "Cannot connect to $db: $DBI::errstr\n" unless (defined $dbh);

my $sth = $dbh->prepare("INSERT INTO clients VALUES('tipo','linguaggio','progetto',1);") or die "$dbh->errstr\n";
my $rc = $sth->execute or die "$dbh->errstr\n";

The error message is

[Wed Feb 24 13:03:27 2010] myscript.cgi: DBD::mysql::st execute failed: Column count doesn't match value count at row 1 at myscript.cgi.
[Wed Feb 24 13:03:27 2010] myscript.cgi: DBI::db=HASH(0x8a30c60)->errstr

I am desperated. What is the problem?

Last edited by shifter; 02-24-2010 at 06:12 AM.
Old 02-24-2010, 08:46 AM   #2
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,293

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335

It means the SQL you are trying to execute is not correct.

INSERT INTO clients VALUES('tipo','linguaggio','progetto',1)

The table called clients does not have 4 columns. If you want to insert and use default values for the other columns, you need to name each of the columns in the SQL:

INSERT INTO clients (columnName1,columnName2,columnName3,columnName4) VALUES ('tipo','linguaggio','progetto',1)
Old 02-24-2010, 07:42 PM   #3
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,396

Rep: Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395Reputation: 2395
Never(!) rely on inserting without specifying the col names.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Faillog does not count failed login attempts SecondMet Linux - Security 11 04-19-2010 05:11 AM
Need a way to count sub-directories and get a total count Mo-regard Linux - Newbie 1 08-14-2009 09:10 AM
SWATCH::not able to get the correct match count when i use regular expression vjayraghavan Linux - Newbie 0 03-27-2009 01:16 AM
Should posts in general count on your post count? Joey.Dale General 16 01-27-2004 01:31 AM
ssh failed login count - where is it? mbhenry Linux - Security 1 11-13-2003 11:35 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:14 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration