成功后登录页面不会重定向,PHP

时间:2018-08-29 15:28:02

标签: php html mysqli

大家好。在连接登录页面以处理输入并移至另一个窗口时,我需要帮助。我对PHP相当陌生,并且通过遵循一些教程来从事这个项目。我想我迷路了,把代码弄乱了。请问喜欢的人告诉我我哪里错了吗?谢谢

<?php
include("includes/checklogin.php");
?>

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Login Page</title>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
  <div class="loginbox">
    <img src="images/matatu.png" class="matatu">
    <form action="landing page.php" method="POST">
      <p>Username</p>
      <input type="text" id="username" name="username" placeholder="Enter Username">
      <p>Password</p>
      <input type="password" id="password" name="password" placeholder="Enter Password">
      <input type="submit" name="" placeholder="Login">
      <a href="#">Forgot your password?</a></form><br>
    <a href="registration.php">Don't have an account?</a><br>
  </div>
  <div class="footer">
    <p>&copy 2018</p>
  </div>
</body>

</html>



<?php
$error=''; //Variable to Store error message;
if(isset($_POST['submit'])){
    if(empty($_POST['username']) || empty($_POST['password'])){
        $error = "Username or Password is Invalid";
    }
    else
    {
        //Define $user and $pass
        $user=$_POST['username'];
        $pass=$_POST['password'];
        //Establishing Connection with server by passing server_name, user_id and pass as a parameter
        $conn = mysqli_connect("localhost", "root", "Safaricom2017");
        //Selecting Database
        $db = mysqli_select_db($conn, "ticketing_system");
        //sql query to fetch information of registerd user and finds user match.
        $query = mysqli_query($conn, "SELECT * FROM admin WHERE password='$pass' AND username='$user'");

        $rows = mysqli_num_rows($query);
        if($rows == 1){
            header("Location: landing page.php"); // Redirecting to other page
        }
        else
        {
            $error = "Username of Password is Invalid";
        }
        mysqli_close($conn); // Closing connection
    }
}

?>

0 个答案:

没有答案