我想将数据插入数据库,但它显示以下错误:Can't call method "execute" on an undefined value at C:/wamp/bin/apache/apache2.2.22/cgi-bin/ova/laura/shto.pl line 47.
my $q= new CGI;
print $q->header;
print $q-> start_html(
-title => " ",
);
my $db = "peoples";
my $user = "root";
my $pass = "";
my $host ="127.0.0.1";
my $dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass);
my $name = $q->param("Name");
my $surname = $q->param("Surname");
my $$gender = $q->param("Gender");
my $dId = $q->param("pID");
my $departamentiId = $q->param("dID");
my $sql = "INSERT INTO person (Name, Surname, Gender, pID, dID)
VALUES ('$name', '$surname', '$gender','$pId','$dId')";
my $sth = $dbh->prepare($sql);
my $sth->execute() or die $DBI::errstr;
my $sth->finish();
my $dbh->commit or die $DBI::errstr;
可能是什么错误?