in reply to DBI quote: invalid number of parameters

DBI is throwing an error because you are not passing anything to quote. The code you posted looks like it is passing something to quote; however, param('something') can retrun an empty list when called in list context. So what you basically end up doing is $dbi->quote(), and DBI throws an error to protect you from yourself.

So, to get it to do what you want, you can do a $dbi->quote(scalar(param('username'))), or maybe $dbi->quote(param(('username') or undef)).

Also you might want to try using placeholders instead of using quote() on each value. While placeholders will not get you around the 'param returning an empty list problem', placeholders end up being much cleaner. Something like this:
my $sth = $dbh->prepare("INSERT INTO member (nickname, password, first +_name, last_name, email, country, homepage, im_type, im_id, info) VAL +UES (?,?,?,?,?,?,?,?,?,?)"); $sth->execute( map {scalar(param($_))} qw(username password1 firstname lastname email imtype imid info ) );

Replies are listed 'Best First'.
Re: Re: DBI quote: invalid number of parameters
by Baiul (Acolyte) on Feb 23, 2003 at 23:54 UTC
    First off thanks for the help to both of you :).

    Next I tried both methods of using the placeholders and now I am getting a different error as follows:

    DBD::mysql::st execute failed: Column 'nickname' cannot be null at usersetup2.cgi line 378.

    There is most definately a value in the param so I'm not sure what is going wrong with it. Any ideas?
    Thanks again,
    Ubi Concordia Ibi Victoria

      Ok ignore that last post that was an error to due with my own problem hehe. I fixed that up and now it is working perfectly.

      I just wanted to say thanks again to you both! You have saved me a lot of problems and I am very happy!

      Ubi Concordia Ibi Victoria