你好我想从数据库中删除数据后在另一个位置重定向。但它显示以下错误:状态:302找到位置:
my $q= new CGI;
print $q->header ('Text/html');
print $q-> start_html(
-title => "",
);
my $db = "peroples";
my $user = "root";
my $pass = "";
my $host="127.0.0.1";
my $dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass);
my $action_delete = $q->param('delete');
my $action_update = $q->param('update');
if($action_delete + 0 > 0) {
my $row_id = $action_delete + 0;
my $sqlQuery = $dbh->prepare("DELETE FROM peoples WHERE ID = $row_id");
$sqlQuery->execute;
print $q->redirect(-uri => 'http://localhost/cgi-bin/peoples.pl',);
答案 0 :(得分:5)
在启动HTML之前放置重定向标头。首先是print $q->redirect
,然后是$q->start_html
。
了解HTTP message的外观,以及其标题和正文部分的工作原理。如果您将重定向放入正文中,则无法正常工作。