提交表单后重定向到另一个页面

时间:2015-05-24 20:01:12

标签: php html

我试图这样做:当你提交表格时,它会给你一条消息,比如"你已经被压倒在课堂上,并会在几秒钟内被重定向。"然后它重定向到某个页面。我无法让它发挥作用。这是我的代码:

<html>
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
$mysql_host     = "localhost";
$mysql_username = "";
$mysql_password = "";
$mysql_database = "a";
$mysql_database2 = "";

$sub = $_POST['subject'];
$mysqli2  = new Mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database2) or die(mysqli_error());
$head = $mysqli2->query("SELECT head FROM class WHERE subject = '$sub'")->fetch_object()->head; 

$status = 1;
$mysqli  = new Mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database) or die(mysqli_error());
$prepare = $mysqli->prepare("INSERT INTO `Overrides`(`name`,`mname`,`fname`,`sid`,`email`,`phone`,`sc`,`subject`,`section`,`semester`,`professor`,`status`,`dean`,`head`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$prepare->bind_param("ssssssssssssss", $_POST['name'], $_POST['mname'], $_POST['fname'], $_POST['sid'], $_POST['email'], $_POST['phone'], $_POST['Scolarship'], $_POST['subject'], $_POST['section'], $_POST['semester'], $_POST['professor'], $status, $_POST['dean'], $head);
$prepare->execute();

$name = $_POST['name'];
$mname= $_POST['mname'];
$fname = $_POST['fname'];
$email = $_POST['email'];
$semester = $_POST['semester'];
$sid = $_POST['sid'];
$subject = $_POST['subject'];
$section = $_POST['section'];
$professor = $_POST['professor'];


    ?>

<!DOCTYPE HTML>

<meta charset="UTF-8">
<meta http-equiv="refresh" content="3; url=http://example.com">

<script>
  window.location.href = "http://blahblah.com"
</script>

<title>Page Redirection</title>

<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
If you are not redirected automatically, follow the <a href='http://blahblah.com'>link to example</a>

<?php
print 'Error : ('. $mysqli->errno .') '. $mysqli->error;
?>
</html>

1 个答案:

答案 0 :(得分:1)

it redirects immediately without showing the text.

That's what window.location.href do. Wrap it in setTimeout

setTimeout(function () {
    window.location.href = "http://blahblah.com";
}, 3000); // call after 3 seconds