无法完成空白页面上的登录会话重定向

时间:2019-05-23 14:24:45

标签: html database login connectivity

因此,假设我的数据库凭据正确:为什么要在空白的connect.php页面上重定向?

我都曾尝试过xampp和在线数据库,但结果仍然相同。我想念什么?

登录页面内的表单:

<link rel="stylesheet" type="text/css" href="style.css">
<div id="Sign-In" class="content">
<div class="title">Login</div>
 <form method="POST" action="connect.php">
   <input name="username" type="text" placeholder="Username"/>
    <input name="password" type="password" placeholder="Password"/>
    <input type="checkbox" id="rememberMe"/>
    <label for="rememberMe"></label><span>Remember Me</span>
    <input type="submit" value="Login"/>
 </form>
 <div class="already">Don't have an account? <a rel="nofollow" rel="noreferrer"href="SignUp/index.html">Sign Up</a></div>

Connect.php文件

<?php
 session_start(); // Starting Session
 $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 $username and $password
    $username = $_POST['username'];
    $password = $_POST['password']; 
    // mysqli_connect() function opens a new connection to the MySQL server.
    $conn = mysqli_connect("localhost", "id8813522_users", "123321", "id8813522_usersdb");
    // SQL query to fetch information of registerd users and finds user match. 
    $query = "SELECT username, password from members where username=? AND password=? LIMIT 1";
     // To protect MySQL injection for Security purpose
       $stmt = $conn->prepare($query);
       $stmt->bind_param("ss", $username, $password);
       $stmt->execute();
       $stmt->bind_result($username, $password);
       $stmt->store_result();
       if($stmt->fetch()) //fetching the contents of the row {
       $_SESSION['login_user'] = $username; // Initializing Session
       header("location: profile.php"); // RedirectingToProfilePage
      } 
     mysqli_close($conn); // Closing Connection 
    } 

    ?>  

我希望在profile.php页面上处于重定向状态(此操作正在进行中),但是我得到了一个空白的connect.php页面

0 个答案:

没有答案