Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    79
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    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?

  • #2
    120
    120 is offline
    Regular Coder
    Join Date
    Nov 2009
    Location
    UK
    Posts
    105
    Thanks
    6
    Thanked 15 Times in 15 Posts
    Where are your field names?

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

  • #3
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    if you have a auto_increment PK, you need to alow for that in your insert statement.

    Code:
    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
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #4
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts

    session not starting until second page opened.

    posted in error.
    Last edited by bazz; 02-25-2010 at 07:36 PM.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •