我想在两个IF语句成功完成后,将用户重定向到一个新页面。我希望它转发到booking.php
这就是我现在拥有的:
<?php
//connect to database
$dbConnect = mysqli_connect('xxxxxxx', 'xxxxxx','xxxxx')
or die("<p>The database server is not available.</p>");
$dbSelect = mysqli_select_db( $dbConnect,'sxxxxxx_db' )
or die("<p>The database is not available.</p>");
if(empty($_GET['namefield']) || empty($_GET['pwdfield']) || empty($_GET['cpwdfield']) || empty($_GET['emailfield']) || empty($_GET['phonefield']) )
{
Echo "Not all details have been entered";
}
ELSE
{
$name = $_GET['namefield'];
$email = $_GET['emailfield'];
$phone = $_GET['phonefield'];
//Inserts Name, Password ,email and phone in the MySQL table
$sql = "INSERT INTO customer (Name,Email,Phone) VALUES ("$name","$email","$phone") ";
mysqli_query($dbConnect,$sql);
}
//check password
if ($_GET["pwdfield"] == ($_GET['cpwdfield']))
{
$password = $_GET['pwdfield'];
$email = $_GET['emailfield'];
$sql = "UPDATE customer SET Password='".$password."' WHERE Email='".$email."'";
mysqli_query($dbConnect,$sql);
//Or die ("<p>Data unable to enter into database.</p>"."<p>Error code ". mysqli_errno($dbConnect). ": ".mysqli_error($dbConnect)). "</p>";
}
ELSE
{
$sql = "DELETE from customer where Password ='".$password."'";
mysqli_query($dbConnect,$sql);
echo("<br>Password did not match! ");
// failed
}
mysqli_close($dbConnect);
?>
如有任何帮助,将不胜感激
谢谢。
更新:
我知道我可以使用头,但我需要帮助只在if语句正确之后进行引导。
尝试添加要重定向的位置,
header('Location: booking.php');
您可以使用header命令,http://php.net/manual/en/function.header.php
您可以使用
header( 'Location: booking.php' );
为此。(当然,这取决于您的booking.php文件的路径。)
使用PHP的http_redirect()重定向到给定的url。
语法:
bool http_redirect ([ string $url [, array $params [, bool $session = false [, int $status = 0 ]]]] )
参考:
检查http_redirect
尝试使用脚本重定向时未传递IF标头信息。
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.location.href='sample.php';
</SCRIPT>");