DB is empty, but PDO execute returns bool(True)

I wanna make login to school system for students and teachers.
    $query = $pdo->prepare("SELECT `username`, `password` FROM `teachers` WHERE `username` = :username");
    $result = $query->execute(array(
    ":username" => $username));

    if($result) {
       $_SESSION["username"]["who"] = array($username, "teacher");
       echo("<script>location.href = 'home.php';</script>");
    } else {
       $query = $pdo->prepare("SELECT `username`, `password` FROM `students` WHERE `username` = :username");
       $result = $query->execute(array(
       ":username" => $username));

       if($result) {
          $_SESSION["username"]["who"] = array($username, "student");
          echo("<script>location.href = 'home.php';</script>");
       } else {
          echo("<script>alert('Error.'); location.href = 'index.php';</script>");
       }
    }
I have only one username in my students database. But If I can try login with random username, I every get $result = True. Why is $result true, when the tables of teachers are empty?

Комментарии

Популярные сообщения из этого блога

FillChar and StringOfChar under Delphi 10.2 for Win64 Release Target

TeXnicCenter does not work with Adobe anymore