#!c:/perl/bin/perl.exe
use DBI;
$,="\t";
use CGI ":standard";
$name=param("name");
$capacity=param("capacity");
print"content-type:text/html\n\n";
print"<html>\n";
$db=DBI->connect("dbi:mysql:Jo") or die"\n Error($DBI::err):$DBI::errstr\n";
$update='insert into fish values($name,$capacity)';
$s=$db->do($update);
$db->disconnect();
print"<b><font color=\"990000\">Database updated</font color></b>";
Can anyone tell me what I'm doing wrong as this code doesn't update the database at all?
Thanks
$update = "INSERT [mysql.com] into fish values($name,$capacity)";
$update = qq{INSERT [mysql.com] into fish values($name,$capacity)};
$update = END_OF_SQL;
INSERT [mysql.com] into fish values($name,$capacity)
END_OF_SQL
$update = "END_OF_SQL";
INSERT [mysql.com] into fish values($name,$capacity)
END_OF_SQL
Make sure that you escape all special characters in
$name and $capacity. Andreas
or die $db->errstr; to your do method call. This will report any db errors. Using placeholders (?) will safe you from having to escape any special characters in $name and $capacity. And you will not need to enclose non-numeric values in single quotes.
$db->do('insert into fish values(?,?)', undef, $name, $capacity)
or die $db->errstr;
When AutoCommit is off you will need to commit changes after you are finished with your transactions by calling
$db->commit. Andreas