title: PHP Error - Call to a member function execute() on a non-object
body: <p>I wrote thte following piece of code:</p>
  
  <pre><code>&lt;?php
  
  $username = $_POST['user'];
  $password = $_POST['pass'];
  
  $db = new PDO ('mysql:host=localhost;dbname=ozdatabase;charset=utf8', 'root', '');
  $db-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  $db-&gt;setAttribute(PDO::ATTR_ERRMODE, 'ERRMODE_EXCEPTION');
  
  $stmt = $db-&gt;prepare("SELECT id, users FROM ozusers WHERE username=? AND password=?");
  $stmt-&gt;execute(array($username, $password));
  $rows = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
  
  $id = $rows['id'];
  $user = $rows['users'];
  
  if ($id) {
      print "Logged";
  }
  
  else {
      print "not good";
  }
  
  ?&gt;
  </code></pre>
  
  <p>This is the HTML Form:</p>
  
  <pre><code>&lt;form id='login' action='login.php' method='post' accept-charset='UTF-8'&gt;
  &lt;fieldset &gt;
  &lt;LEGEND&gt;COMMUNICATION&lt;/LEGEND&gt;
  &lt;input type='hidden' name='submitted' id='submitted' value='1' /&gt;
  
  &lt;label for='username' &gt;UserName*:&lt;/label&gt;
  &lt;input type='text' name='user' id='username' maxlength="50" /&gt;
  
  &lt;label for='password' &gt;Password*:&lt;/label&gt;
  &lt;input type='password' name='pass' id='password' maxlength="50"&gt;
  
  &lt;input type='submit' name='Submit' value='Submit' /&gt;
  
  &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I get an error when trying to login in the page and it's written:
  "Fatal error: Call to a member function execute() on a non-object in.. On line 15"</p>
  
  <p>Why is this happening? I followed best practice guide and it showed to use the "execute()" function exactly like that..</p>
  
  <p>Thanks</p>