Discussion:
problem with passing variables
Mark Haney
2011-12-30 16:17:30 UTC
Permalink
I'm not sure if this is the right list for this, so bear with me. If it
isn't I'll be glad to post it on the correct one.

I've got a problem with passing variables to a SQL server inside a CGI
script. My code is like this:

my $begin_time = "2011-11-16 11:00:00";
my $end_time = "2011-11-16 12:00:00";

my $dbh = DBI->connect('dbi:mysql:database=embdev', 'user', 'password');

my $sql = q/SELECT * FROM events WHERE date BETWEEN $begin_time and
$end_time/;

my $sth = $dbh->prepare($sql);
$sth->execute();

I'm not sure why it's not using the the variables, can someone point out
what I'm doing wrong?

-----
Mark Haney
--
To unsubscribe, e-mail: beginners-cgi-***@perl.org
For additional commands, e-mail: beginners-cgi-***@perl.org
http://learn.perl.org/
nat
2011-12-30 16:19:39 UTC
Permalink
Mark,
I'm kind of new with perl, but from what I see, you're using a single
quote when defining $sql, and it should be qq for the interpolated string.
With the single quote (q) it is a literal. Hope this helps.
Post by Mark Haney
I'm not sure if this is the right list for this, so bear with me. If it
isn't I'll be glad to post it on the correct one.
I've got a problem with passing variables to a SQL server inside a CGI
my $begin_time = "2011-11-16 11:00:00";
my $end_time = "2011-11-16 12:00:00";
my $dbh = DBI->connect('dbi:mysql:database=embdev', 'user', 'password');
my $sql = q/SELECT * FROM events WHERE date BETWEEN $begin_time and
$end_time/;
my $sth = $dbh->prepare($sql);
$sth->execute();
I'm not sure why it's not using the the variables, can someone point out
what I'm doing wrong?
-----
Mark Haney
--
nat
enrgeeman.com
--
To unsubscribe, e-mail: beginners-cgi-***@perl.org
For additional commands, e-mail: beginners-cgi-***@perl.org
http://learn.perl.org/
Loading...