How do i redirect from a php page to html page ,header isnt working in the following code
<?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);
?>
How do i redirect from here and why is the above code not working?
I think MarkB has your answer. That is, the correct syntax would be:
header('Location: http://localhost/submit.html',true);
However, if that doesn't solve the problem you can try this:
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=submit.html">';
header()
will fail if any other output was sent to the browser previously, and the above will succeed in those cases.
you can't use header()
after you already sent text to the browser, in this case from include "submit.html";