0

次のコードでエラーが発生します。

#!C:/usr/bin/perl -w

use CGI;
use strict;
use DBI();
use CGI::Carp qw(fatalsToBrowser);


print "content-type: text/html; charset=iso-8859-1\n\n";

my $q=new CGI;
my $ename=$q->param('ename');
my $email=$q->param('email');

print $q->header;
print "<br>$ename<br>";


#connect to database.
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost","root","mukesh",
          {'RaiseError' => 1});

eval {$dbh->do("CREATE TABLE IF NOT EXISTS emp (ename VARCHAR(20), email VARCHAR(50))")};
print "<br>creating table emp failed: $@<br>" if $@;


my $sql="INSERT INTO emp(ename,email) values('$ename','$email')";

my $sth = $dbh->prepare($sql) or die "Can't prepare $sql:$dbh->errstrn";
#pass sql query to database handle


my $rv = $sth->execute() or die "can't execute the query: $sth->errstrn";

my @row;
while (@row = $sth->fetchrow_array) {
print join(", ",@row);
}

$sth->finish();
$dbh->disconnect();

if ($rv==1){
print "<br>Record has been successfully updated !!!<br>";
}else{
print "<br>Error!!while inserting record<br>";
exit;
}

提案してください。何が問題なのですか。このコードを削除すると正常に動作します。

my @row;
while (@row = $sth->fetchrow_array) {
print join(", ",@row);
}
4

1 に答える 1