簡體   English   中英

提交表單后重定向到另一個頁面

[英]Redirecting to another page after form is submitted

我正在嘗試執行以下操作:提交表單時,它會給您類似“您已被覆蓋到班級,將在幾秒鍾內重定向”的消息,然后將其重定向到某個頁面。 我無法使其正常工作。 這是我的代碼:

<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>

它立即重定向而不顯示文本。

那就是window.location.href所做的。 將其包裝在setTimeout中

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM