title: php login script not working and , it doesnt redirect back to the dashboard
body: <p>i have not been able to get this, i have been on this for days ,i dont know if its from the login page or the dashboard , but my login script doesnt redirect to the dashboard </p>
  
  <p>i have tried alot of things and even added an echo at every line of code , it shows that , the scripts get to the redirect and actually redirects but still comes back to the login page</p>
  
  <pre><code>&lt;?php require 'sqlconnect.php' ?&gt;
  
  &lt;?php
      session_start(); 
  ?&gt;
  &lt;?php
  
      $email= '';
      $password = '';
  
      $errors = '';
      $success = '';
  
      if(isset($_REQUEST['login'])){
  
          $email = $_REQUEST['email'];
          $password = $_REQUEST['password'];
  
          if(empty($email)){
              $errors .= '&lt;div class="alert alert-danger" role="alert"&gt;
                          Email field is empty.
                      &lt;/div&gt;';
              }
          if(empty($password)){
              $errors .= '&lt;div class="alert alert-danger" role="alert"&gt;
                          Password field is empty.
                      &lt;/div&gt;';
          }
          if(!empty($email) and !empty($password)){
  
              $confirm_info = mysqli_query($connection, "SELECT * FROM users WHERE email = '$email' AND password = '$password'");
  
              if(mysqli_num_rows($confirm_info) &gt;= 1){
                  echo "if statement";
  
                  while($results = mysqli_fetch_assoc($confirm_info)) {
                      $token = $results['token'];
                      $token = $_SESSION['token'];
                      header("Location: dashboard/profile.php");
                  }
              }else{
                  $errors .= '&lt;div class="alert alert-danger" role="alert"&gt;
                              Login credentials doesn\'nt exist is our database.
                          &lt;/div&gt;';
              }
          }
      }
  ?&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  
          &lt;form class="login100-form validate-form" method="POST" action="login.php"&gt;
              &lt;span class="login100-form-title p-b-37"&gt;
                  Sign In
                  &lt;!-- &lt;i class="fa fa-home uk-align-center uk-text-center"&gt;&lt;/i&gt; --&gt;
              &lt;/span&gt;
              &lt;?php
                  echo $errors;
                  //echo $success;
              ?&gt;
              &lt;br&gt;
  
              &lt;div class="wrap-input100 validate-input m-b-20" data-validate="Enter username or email"&gt;
                  &lt;input class="input100" type="email" name="email" placeholder="email" value="&lt;?php echo $email ?&gt;"&gt;
                  &lt;span class="focus-input100"&gt;&lt;/span&gt;
              &lt;/div&gt;
  
              &lt;div class="wrap-input100 validate-input m-b-25" data-validate = "Enter password"&gt;
                  &lt;input class="input100" type="password" name="password" placeholder="password"&gt;
                  &lt;span class="focus-input100"&gt;&lt;/span&gt;
              &lt;/div&gt;
  
              &lt;div class="container-login100-form-btn"&gt;
                  &lt;button class="login100-form-btn" id="login" name="login"&gt;
                      Sign In
                      &lt;i class="fa fa-spinner fa-spin" id="spinner" style="display: none"&gt;&lt;/i&gt;
                  &lt;/button&gt;
              &lt;/div&gt;
              &lt;div class="text-center p-t-57 p-b-20"&gt;
                  &lt;span class="txt1"&gt;
                  &lt;a href="forgetpassword.php" class="txt2 hov1"&gt;
                      forget password
                      &lt;i class="fa fa-long-arrow-right m-l-5"&gt;&lt;/i&gt;
                  &lt;/a&gt;
                  &lt;/span&gt;
              &lt;/div&gt;
  
              &lt;div class="text-center p-t-57 p-b-20"&gt;
                  &lt;span class="txt1"&gt;
                      Or Create  an account
                  &lt;/span&gt;
              &lt;/div&gt;
  
  
              &lt;!-- &lt;div class="flex-c p-b-112"&gt;
                  &lt;a href="#" class="login100-social-item"&gt;
                      &lt;i class="fa fa-facebook-f"&gt;&lt;/i&gt;
                  &lt;/a&gt;
  
                  &lt;a href="#" class="login100-social-item"&gt;
                      &lt;img src="login/images/icons/icon-google.png" alt="GOOGLE"&gt;
                  &lt;/a&gt;
              &lt;/div&gt; --&gt;
  &lt;!-- 
              &lt;div class="text-center"&gt;
                  &lt;a href="#" class="txt2 hov1"&gt;
                      Sign Up
                  &lt;/a&gt;
              &lt;/div&gt; --&gt;
          &lt;/form&gt;
          &lt;div class="container-login100-form-btn"&gt;
              &lt;a href="signup.php" class="txt2 hov1 text-light"&gt;
                  &lt;button class="signin100-form-btn"&gt;
                     Sign Up
                  &lt;/button&gt;
              &lt;/a&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And this is the dashboard profile page code</p>
  
  <pre><code>&lt;?php require '../sqlconnect.php' ?&gt;
  &lt;?php 
    session_start();
    $token = $_SESSION['token'];
      if(!isset($_SESSION['token'])){
          header("Location: ../login.php");
          exit();
      }else{
  
        $all_details = mysqli_query($connection, "SELECT * FROM users WHERE token = '$token'");
  
        if(mysqli_num_rows($all_details)){
  
          $results = mysqli_fetch_assoc($all_details);
          $id = $results['id'];
          $token = $results['token'];
          $email = $results['email'];
          $first_name = $results['first_name'];
          $is_admin = $results['is_admin'];
          $last_name = $results['last_name'];
          $usernam = $results['username'];
          $image_name = $results['image_name'];
          $image_dir = $results['image_dir'];
  
          // echo $username;
          }
      }
  ?&gt;
  </code></pre>