我正在制作一个连接到数据库“人民”的代码,从那里获取数据,我需要做的是使用一个按钮来获取单击此按钮并删除或更新的人的 ID。问题是我不知道如何使这个 i perl 因为在其他语言中我做到了。
my $q= new CGI;
print $q->header;
print $q-> start_html(
-title => "Main",
-style => {-src =>'/media/css/ui-lightness/jquery-ui-1.10.3.custom.css" rel="stylesheet' },
-script => [
{ -src=>'/media/js/jquery-1.9.1.js'},
{ -src=>'/media/js/jquery-ui-1.10.3.custom.js' }
]
);
print $q->start_form;
print $q->table({},
$q->Tr(
$q->th('Name', 'Surname', 'Age')
));
# Connect to the database
## mysql user database name
my $db = "student";
## mysql database user name
my $user = "root";
## mysql database password
my $pass = "";
## user hostname : This should be "localhost" but it can be diffrent too
my $host="127.0.0.1";
## SQL query
my $query = "select Name,Surname,Age from student";
my $dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass);
my $sqlQuery = $dbh->prepare($query)
or die "Can't prepare $query: $dbh->errstr\n";
my $rv = $sqlQuery->execute
or die "can't execute the query: $sqlQuery->errstr";
while ( my ($Name, $Surname, $Age) = $sqlQuery->fetchrow_array() ) {
print STDOUT "$Name $Surname $Age";
$q->button( print $q->button(
-id => 'leletebtn',
-name => 'submit_form',
-value => 'Delete',
)
)
}
print $q->end_form;
print $q->end_html;