title: PHP SQLite PDO Check if user is in table?
body: <p>I'm trying to create a script that checks if the provided username is in the table "users", but the "if" statement is always returned false. The users table only has the one column "username", listing all the users. What am I doing wrong?</p>
  
  <pre><code>$dbh = new PDO("sqlite:db.sqlite");
  $stmt = $dbh-&gt;prepare("SELECT username from users where username = :name");
  $stmt-&gt;bindParam(":name", $user);
  $stmt-&gt;execute();
  
  if($stmt-&gt;rowCount() &gt; 0)
  {
      //in the table
  }
  else{
      //not in the table
  }
  </code></pre>
  
  <p>The whole script:</p>
  
  <pre><code>&lt;?php
  require_once 'mclogin.class.php';
  $api = new MinecraftAPI();
  $user = $_POST['user'];
  $password = $_POST['pword'];
  if($api-&gt;login($user, $password)){
  print $user;
  $dbh = new PDO("sqlite:db.sqlite");
  $stmt = $dbh-&gt;prepare("SELECT username from users where username = :name");
  $stmt-&gt;bindParam(":name", $user);
  $stmt-&gt;execute();
  
  if($stmt-&gt;rowCount() &gt; 0)
  {
      echo "You are whitelisted";
  }
  else{
      echo "You are not whitelisted";
  }
  
  }else{
  echo "Bad login";
  }
  ?&gt;
  </code></pre>
  
  <p>the page that send the info:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
        &lt;form name="input" action="login.do.php" method="post"&gt;
  Username: &lt;input type="text" name="user"&gt;
  Password: &lt;input type="password" name="pword"&gt;
  &lt;input type="submit" value="Submit"&gt;
        &lt;/form&gt;  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>