-1

如何从 php 页面重定向到 html 页面,标题在以下代码中不起作用

<?php include "submit.html";
define('DB_NAME','form');
define('DB_USER','root');
define('DB_PASSWORD','toor');
define('DB_HOST','localhost');
$link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if(!$link)
{
    die('could not connect : ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME,$link);
if(!$db_selected)
{
    die('Can\'t use ' .DB_NAME . ': ' .mysql_error());
}
$value1 = $_POST['fname'];
$value2 = $_POST['Place'];
$value3 = $_POST['Country'];
$value4 = $_POST['rname'];
$value5 = $_POST['food'];
$value6 = $_POST['ambience'];
$value7 = $_POST['service'];
$value8 = $_POST['clean'];
$value9 = $_POST['pfacility'];
$value10 = $_POST['Entertainment'];
$value11 = $_POST['suggestions'];
$sql = "INSERT INTO demo1 (fname,Place,Country,rname,food,ambience,service,clean,Parking_facilities,Entertainment,suggestions) VALUES ('$value1','$value2','$value3','$value4','$value5','$value6','$value7','$value8','$value9','$value10','$value11')";
if(!mysql_query($sql))
{
    die('Error: ' . mysql_error());
}
mysql_close();
header('Location: localhost/submit.html',true);
?>

我如何从这里重定向,为什么上面的代码不起作用?

4

2 回答 2

0

header()在您已经将文本发送到浏览器后,您将无法使用,在这种情况下,来自include "submit.html";

http://php.net/manual/en/function.header.php

于 2013-10-08T18:42:22.007 回答
0

我认为 MarkB 有你的答案。也就是说,正确的语法是:

header('Location: http://localhost/submit.html',true);

但是,如果这不能解决问题,您可以尝试以下操作:

echo '<meta HTTP-EQUIV="REFRESH" content="0; url=submit.html">';

header()如果之前将任何其他输出发送到浏览器,则将失败,并且在这些情况下上述操作将成功。

于 2013-10-08T18:39:07.167 回答