title: SQLSTATE[HY000]: General error with PHP and PDO
body: <p>I have a little login script.</p>
  
  <pre><code>function login($sql) {
  try {                   
      $fbhost = "localhost";
      $fbname = "foodbank";
      $fbusername = "root";
      $fbpassword = "";
      $DBH = new PDO("mysql:host=$fbhost;dbname=$fbname",$fbusername,$fbpassword);
      $DBH-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      $STH = $DBH-&gt;query($sql);       
      $STH-&gt;setFetchMode(PDO::FETCH_ASSOC);
  
      session_start();        
      if ($row = $STH-&gt;fetch()) {
          $_SESSION['username'] = "$row[username]";
          header("Location:index.php");   
      }
  } catch(PDOException $e) {
      echo $e-&gt;getMessage();
  }
  }
  </code></pre>
  
  <p>EDITS: </p>
  
  <p>index.php</p>
  
  <pre><code>$sql = "SELECT username from users where username = ". $_POST['username'] ." AND password = ". $_POST['password'] ."";
  login($sql);
  </code></pre>
  
  <p>Changed above from insert to select query. Now I get new error:
  <strong>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pvtpyro' in 'where clause'</strong></p>