...

View Full Version : DBD::mysql::st execute failed: Column count doesn't match value count at row 1



dark0s
02-24-2010, 12:11 PM
I have the following perl/DBI script:

#!/usr/bin/perl

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";

$dbh->disconnect;
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?

120
02-24-2010, 07:54 PM
Where are your field names?


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

AS IN


INSERT INTO clients (field1,field2,field3,field4) VALUES('tipo','linguaggio','progetto',1);

bazz
02-25-2010, 04:42 AM
if you have a auto_increment PK, you need to alow for that in your insert statement.



INSERT INTO clients
VALUES('', ?, ?, ?, ?);

$sth->execute('tipo','linguaggio','progetto',1);

or better

$sth->execute($tipo,$linguaggio,$progetto,$uno) or die "execute statement failed: $DBI::errstr\n";


bazz

bazz
02-25-2010, 05:07 AM
posted in error.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum