2015-05-24 148 views
0

我正在尝试这样做:当您提交表单时,它会为您提供一条消息,如“您已被覆盖到该类并将在几秒钟内重定向”然后它重定向到某个页面。我无法使其工作。这里是我的代码:提交表单后重定向到另一个页面

<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

_I'm无法使它工作._ - 会发生什么? – Federkun

+0

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

回答

1

立即重定向,而不显示文本。

这就是window.location.href所做的。把它裹在setTimeout

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

我该如何实现整个代码? –

+0

即时新手; / –