title: Login function always returns true
body: <p>I am having an issue getting a login function to work. It always returns true even though I enter the wrong credentials. Can anyone tell me why this is?</p>
  
  <p>here is the function</p>
  
  <pre><code>public function login($username, $password) {
      global $pdo;
  
      $users = new Users;
      $user_id = $users-&gt;get_user_id($username);
  
      $query = $pdo-&gt;prepare("SELECT * FROM `users` WHERE `username` = ? AND `password` = ?");
      $query-&gt;bindValue(1, $username);
      $query-&gt;bindValue(2, $password);
      $query-&gt;execute();
  
      if (!$query) {
          return false;
      }
  
      return $user_id;
  }
  </code></pre>
  
  <p>and here is where it is implemented.</p>
  
  <pre><code>if (isset($_SESSION['user_id']) === true) {
      header('Location: backend.php');
      exit();
  } else {
  if (empty($_POST) === false) {
      $username = $_POST['username'];
      $password = $_POST['password'];
  
      if (empty($username) === true || empty($password) === true) {
          $errors[] = 'All fields are required!';
      } else {
          $login = $users-&gt;login($username, $password);
  
          if ($login === false) {
              $errors[] = 'Username or password incorrect!';
          } else {
              $_SESSION['user_id'] = $login;
              header('Location: backend.php');
              exit();
          }
      }
  }
  </code></pre>