[plug] Perl/DBI syntax
John Usher (Maptek)
John.Usher at perth.maptek.com.au
Tue Sep 9 14:13:24 WST 2003
A bit of error checking might help you locate the problem...
if (!defined $dbh)
{
$errstr = "Not connected to a database.";
return undef;
}
my $sth = $dbh->prepare($query);
if (!defined $sth)
{
my $err = $dbh->errstr;
$errstr = "Prepare error: $err.";
return undef;
}
my $rv = $sth->execute();
if (!$rv)
{
my $err = $sth->errstr;
$errstr = "Execute error: $err.";
return undef;
}
...John...
-----Original Message-----
From: Nigel Duff [mailto:peregrin at iinet.net.au]
Sent: Tuesday, 9 September 2003 2:03 PM
To: plug at plug.linux.org.au
Hola,
I am trying to connect a cgi script to mysql. Here is what i have;
my $query = $dbh->prepare ("insert into management
(title, item_no, descript, pics, comments, start_date,
end_date, startprice, cost, paid)
values
($fields{TITLE}, $fields{ITEMNO}, $fields{DESCRIPT},
$fields{PICTURES}, $fields{COMMENTS},
$fields{STARTDATE}, $fields{ENDDATE},
$fields{STARTPRICE}, $fields{COST}, $fields{PAIDFOR})");
$query->execute();
print "($fields{TITLE}, $fields{ITEMNO}, $fields{DESCRIPT},
$fields{PICTURES}, $fields{COMMENTS}, $fields{STARTDATE},
$fields{ENDDATE}, $fields{STARTPRICE}, $fields{COST},
$fields{PAIDFOR})";
If I declare the $fields* variables at the start of the script and run
run it from the command line the values are added to the table.
If I call the script from cgi the print line prints the correct values
on the web page but the table doesn't get updated.
Is my mistake glaringly obvious?
Many thanks,
Nigel
More information about the plug
mailing list