I've been stuck on this for some time and I don't seem to be able to figure out what the issue is. I am making a very simple, basic sign in page for my project, however I can't seem to get my 'else' statement to work.
When a username and password are entered correctly, I can successfully get the Sign In message to show up, however if I enter username&password incorrectly, I would want to have no results and still show 'Incorrect username or password' message, however it always shows as blank.
PS: I know about sessions and the rest, I just want to get this sorted before I even attempt to work on those.
I looked elsewhere in the past few hours but I was unable to find any help that could help me troubleshoot.
$user_name = $_POST['username'];
$user_password = $_POST['password'];
if (isset($_POST["username"], $_POST["password"]))  {
    $results = $pdo->query("SELECT user_name, user_password FROM users WHERE user_name = '" . $user_name . "' AND  user_password = '" . $user_password . "'");
    foreach ($results as $result) {
        $result = $pdo->query("SELECT COUNT(*) FROM  users WHERE user_name = '" . $user_name . "' AND  user_password = '" . $user_password . "'")->fetchColumn();
        //var_dump($result);
        if ($result > 0){
            echo "Signed In";
        } else {
            echo "Incorrect Username or Password!";
        }
    }
}
 
     
    