title: Error in PDO page Call to a member function bindValue() on a non-object
body: <p>I am very new to PDO.</p>
  
  <p>I tried making a login page to my website and the code is shown below</p>
  
  <pre><code>&lt;?php
       if(isset($_POST['username'])and isset($_POST['password']))
       { 
  
  session_start();
  $db = new PDO('mysql:host=localhost;dbname=hydra', 'root', '');
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  $query = $db-&gt;query("SELECT * FROM login where username=:username AND password=:password");
      $query-&gt;bindValue(":username", $username, PDO::PARAM_STR);
      $query-&gt;bindValue(":password", $password, PDO::PARAM_STR);
      $query-&gt;execute();
  
      if($query-&gt;rowcount() &gt;0 )
      {
          echo "No Records Found!";
          header('Location: login.php');
      }
      else
      {
          $_SESSION['username'] = $_POST['username'];
          header("Location: home.php");
  
      }
  
  
  
  
             }
           ?&gt;
  </code></pre>
  
  <p>after trying to login, I got this following error :
   <strong>Call to a member function bindValue() on a non-object</strong></p>
  
  <p>Whats wrong with my code?</p>