Reputation: 89
I admit it's been a while since I've used Perl, but this has me stumped.
Here's the issue:
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
use DBI;
print "Content-type: text/html\n\n";
print "<html><head><title></title></head></body>";
my $login = "[email protected]";
my $dbfile = "/var/www/shopsite-data/shopsite_db";
my $sql = qq`SELECT ss_OrderID FROM ss_ORDER WHERE ss_Email=?`;
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "") || die "Cannot connect: $DBI::errstr";
my $sth = $dbh->prepare($sql);
$sth->execute($login) or die $sth->errstr();
while (my @result = $sth->fetchrow_array()) {
print "OrderID: $result[0]<br />";
}
$sth->finish;
print "</body>";
print "</html>";
$dbh->disconnect;
returns nothing, but I get a resultset when logged in with sqlite3 using the same query. I also get a resultset when I change the query from
my $sql = qq`SELECT ss_OrderID FROM ss_ORDER WHERE ss_Email=?`;
to
my $sql = qq`SELECT ss_OrderID FROM ss_ORDER`;
Upvotes: 3
Views: 1139
Reputation:
The obvious problem is the @ inside the double quotes:
my $login = "[email protected]";
is probably coming out as
$login = "admin.com"
and, if you had warnings switched on, a warning would be printed to the log file, because Perl sees @xxxx as an array and tries to interpolate it, then warns because it is empty. That is, assuming you don't have an array called @xxxx. If you do, then you would get all the values of it in the string.
Where you have the email address, use single quotes around it to prevent @xxxx being interpolated as an array:
my $login = '[email protected]';
Or you could use
my $login = "admin\@xxxxx.com";
to prevent the @ starting an interpolation. There may be other problems with your script but this is the most obvious one.
Strangely enough I was just reading about drawbacks of interpolation in Perl.
One more thing: you already have fatalsToBrowser, but
use warnings;
use strict;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
would probably have given you a warning on your browser about uninitialized values, so it might be worth turning warningsToBrowser
on until your script seems to be working (or if it stops working again) (documentation here), and the other two on always.
Upvotes: 13
Reputation: 118128
I believe Kinopiko already pinpointed the problem.
I will add that, if you are going to use CGI.pm
, you should not generate headers by hand. Instead, use CGI::header
.
Also:
print "<html><head><title></title></head></body>";
Note the closing tag for body
when you meant to use an opening tag.
Last, but definitely not least, you should
use strict;
use warnings;
in your scripts.
Upvotes: 4