PHP login page to redirect users based on registration status

I have a login page which redirects users based on registration status. It worked at first but now not redirect again.

This is my php code;

              if($_SERVER["REQUEST_METHOD"] == "POST"){
             $stmt = $conn->prepare("SELECT application_no, password, reg_status FROM 
             students_registration WHERE email = ? ");
             $stmt->bind_param("s", $email);
             $stmt->execute();
              $stmt->bind_result($application_no, $hashedpassword, $reg_status);
             $stmt->store_result();
             if($stmt->num_rows > 0){
             $stmt->fetch();
             if(password_verify($password, $hashedpassword)){
             if($reg_status = 1){
               header("location:homeapplicant.php");
                   }else{
               header("location: admissionform.php");
             $_SESSION["loggedin"] = true;
             $_SESSION["application_no"] = $application_no;
          $_SESSION["email"] = $email;
          $_SESSION["reg_status"] = $reg_status;
          exit();
          //echo "congratulations";
          //echo "<script type=text/javascript>window.location.href = 'biodata.php';</script>";
       }
      }
    else{
        $password_err = "The password you entered was not valid.";
        }
    }
      else{
          $email_err = "No account found with that email.";
     }
     $stmt->close();
    }

    }else{

     }$conn->close();

It worked without checking for reg_status but with reg_status it did not redirect to any page, it just reload login page.

Please where did I get it wrong? I need your help

And the password errors are not showing?

No password error. It worked without checking for reg_status

Then you probably want to switch the order of some things in that if statement. You are redirecting the user prior to telling the session that the user is logged in.

Please do I need to start session before check if reg_status =1 and header redirect

Not sure what you are referring too. The session should already be started for the script. But if you look, you are assigning values to the session, after the header.

Sponsor our Newsletter | Privacy Policy | Terms of Service