将用户重定向到新页面PHP

时间:2015-04-10 07:07:43

标签: php mysqli phpmyadmin

我想在两个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语句正确后直接使用。

5 个答案:

答案 0 :(得分:1)

尝试添加您要重定向的位置,

header('Location: booking.php');

答案 1 :(得分:1)

答案 2 :(得分:1)

您可以使用

header( 'Location: booking.php' );

为此。 (当然,这取决于您的booking.php文件的路径。)

答案 3 :(得分:0)

使用PHP的http_redirect()重定向到给定的URL。

语法:

bool http_redirect ([ string $url [, array $params [, bool $session = false [, int $status = 0 ]]]] )

参考:

检查http_redirect

答案 4 :(得分:0)

在尝试使用脚本重定向时,未传递IF头信息。

   echo ("<SCRIPT LANGUAGE='JavaScript'>
   window.location.href='sample.php';
   </SCRIPT>");