0

您好,我想在从数据库中删除数据后重定向到另一个位置。但它向我显示以下错误:状态: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',);
4

1 回答 1

5

在开始 HTML 之前放置重定向标头。首先print $q->redirect,然后是任何消息正文内容,例如$q->start_html.

了解HTTP 消息的外观,以及它的标头和正文部分是如何工作的。如果将重定向放入正文中,它将无法工作。

于 2013-07-26T09:03:41.743 回答