Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple where statement 2

Status
Not open for further replies.

kevin197

Programmer
Mar 21, 2002
88
GB
I'm trying this:

my $sth = $dbh->prepare( "SELECT count(*) FROM quotesgiven WHERE quotenumber = $info[0] and quotedby = $username" );
$sth->execute or print("Cannot execute statement!<br>".$sth->errstr);
my $rs = $sth->fetchall_arrayref();
my $count = $rs->[0]->[0];

But I'm getting the error:

Cannot execute statement!
Unknown column 'kevin' in 'where clause'

If I leave the second where out it works fine as:

my $sth = $dbh->prepare( "SELECT count(*) FROM quotesgiven WHERE quotenumber = $info[0]" );
$sth->execute or print("Cannot execute statement!<br>".$sth->errstr);
my $rs = $sth->fetchall_arrayref();
my $count = $rs->[0]->[0];

Any ideas?
 
Try
Perl:
my $sth = $dbh->prepare( 'SELECT count(*) FROM quotesgiven WHERE quotenumber = ? and quotedby = ?' );
$sth.execute($info[0], $username);

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thanks stevexff but now I'm getting:

Undefined subroutine &main::execute called at index.cgi line 229

Is that for mysql or postgresql? As I am using mysql
 
should be:

$sth->execute($info[0], $username);

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
My bad...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thank you so much both of you, it works great now :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top