vendredi 5 juin 2020

Why my else condition is beeing executed twice?

I went through this login system with multiusers. Its working fine since it doesn't allow my status_id users '2' to login (inactive status). But when this happens I get the echo message twice on screen.

What am I doing wrong ? I want to validade both user/password, user_type (admin/user) and user_status (1-active, 2-inactive).

Thanks in advance


if(isset($_POST["submit"])){
    $email=$_POST["txtemail"];
    $pass=$_POST["txtpass"];

    $query=mysqli_query($con,"SELECT user_email,user_password,user_type_id, status_id FROM user");
    while($row=mysqli_fetch_array($query))
    {
        $db_email=$row["user_email"];
        $db_pass=$row["user_password"];
        $db_type=$row["user_type_id"];
        $db_user_status=$row['status_id'];

        if($email==$db_email && $pass==$db_pass && $db_user_status=='1' ){
            session_start();
            $_SESSION["email"]=$db_email;
            $_SESSION["type"]=$db_type;

            if($_SESSION["type"]=='1'){
                header("Location:admin/home_admin.php");
            }
            else
                header("Location:user/home_user.php");
        }
        else
            echo("Ups. Algo de errado aconteceu.");
    }}```

Aucun commentaire:

Enregistrer un commentaire