On Sat, 2 Apr 2005, Juan Jose Natera wrote:
Hi,
It works. But when I do:
$StateProvince = 'PA';
my $sql1 = SELECT id, name_short, name_long FROM states WHERE
name_short=$StateProvince;
$sth1 = $dbh-prepare($sql1);
#
$sth1-execute();
I get a message that:
DBD::mysql::st execute failed: Unknown column 'PA' in 'where clause' at
TestDBI.pl line 14.
try this:
$StateProvince = q/'PA'/;
my $sql1 = SELECT id, name_short, name_long FROM states WHERE
name_short=$StateProvince;
or better yet:
$StateProvince = q/'PA'/;
For this version, I think you mean:
$StateProvince = 'PA';
my $sql = 'SELECT id, name_short, name_long FROM states WHERE name_short= ?';
$sth = $dbh-prepare($sql);
$sth-execute($StateProvince);
Basicly $StateProvince in a string value in you sql statement, so you
either single quote yourself, or let DBI do it.
Regards,
JJ