Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: DBI quote: invalid number of parameters

by tantarbobus (Hermit)
on Feb 23, 2003 at 15:55 UTC ( #237901=note: print w/ replies, xml ) Need Help??


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


Comment on Re: DBI quote: invalid number of parameters
Select or Download Code
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,
    Baiul.
    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!

      Baiul.
      Ubi Concordia Ibi Victoria

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://237901]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-07-31 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (248 votes), past polls