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?

Комментарии

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

Skipping acquire of configured file 'contrib/binary-i386/Packages' as repository … doesn't support architecture 'i386'

Connection string for MariaDB using ODBC

Celery like system based on django channels