vendredi 22 octobre 2021

Showing echo message in login page if username doesn't match with sql database in PHP

I'm stuck in a PHP login page logic. Here I wanna show a message in login page that "You're not registered" if login username doesn't match with our database. Here I attached my code. I can see my echo message for wrong username but at the same time getting an error too in browser Undefined variable: the_user_name How can I solve this issue? Or any better idea how can I achieve my goal?

<?php 
    if(isset($_POST['login'])) {
        $user_name = $_POST['username'];

        $user_name = mysqli_real_escape_string($connection, $user_name);

        $query = "SELECT * FROM users WHERE user_name = '$user_name' ";
        $info_chacker = mysqli_query($connection, $query);
        if(!$info_chacker) {
            echo "Something wrong";
        }

        while($row = mysqli_fetch_assoc($info_chacker)) {
            $the_user_name = $row['user_name'];
        }

        if(!empty($user_name) && !empty($user_password)) {
            if($user_name !== $the_user_name) {
                $adminNotice1 = "<p class='warning'> You're not registered </p>";
            }
        }
    } else {
        $adminNotice1 = "";
    }
?>

Aucun commentaire:

Enregistrer un commentaire