mardi 19 juin 2018

Else statement is not applying

Why does the last else statement in my PHP code is not working? When I entered non-existing accounts, it is not displaying the "Incorrect email or password" error message.

<?php

include("connection.php");

$email_id = $password = $emailErr = $passErr = $loginErr = "";

if(isset($_POST["butLogin"])){
    if(empty($_POST["email_id"])){
        $emailErr = "This field cannot be empty!";
    }else{
        $email_id = $_POST["email_id"];
    }

    if(empty($_POST["password"])){
        $passErr = "This field cannot be empty!";
    }else{
        $password = $_POST["password"];
    }

    if($email_id && $password){
        $check_record = mysqli_query($connection, "SELECT * FROM user WHERE password = '$password' AND email = '$email_id'");

        if (mysqli_num_rows($check_record) > 0 ){
            $row = mysqli_fetch_assoc($check_record);
            if(($email_id == $row['email']) && ($password == $row['password'])){
                if($row['user_type'] == 1){
                    header("Location: /php/admin/index");
                }else{
                    header("Location: /php/user/index");
                }
            }else{
                $loginErr = "Incorrect email or password.";
            }   
        }
    }
}

?>

Aucun commentaire:

Enregistrer un commentaire