title: PDO returns wrong value
body: <p>I'm totally new to PDO so I apologize if I made a simple mistake here. Also if this has been answered before. I searched but couldn't find. My problem is that when I print the sessions it prints out 'Array ( [user_id] => 1 )' but the username and password I entered is for user_id 2. I have tried this with a differant username and password and it still gives an id value of 1. So I echoed out $user_id before the session is created and it is 1. But I can't figure out where it is getting this 1 from? Because there is no id of 1 in the database. Can anyone shed some light on this?</p>
  
  <p>Here is the code from my login file:</p>
  
  <pre><code>&lt;?php
  require 'core.inc.php';
  
  if(isset($_POST['username']) &amp;&amp; isset($_POST['password'])) {
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  if (!empty($username) &amp;&amp; !empty($password)) {
      $stmt = $db-&gt;prepare("SELECT password FROM users WHERE username = ?");
      $stmt-&gt;bindParam(1, $username);
  
      $hash = $stmt-&gt;execute();
      $password_verified = password_verify($password, $hash);
  
      if ($password_verified = true) {
          $stmt_id = $db-&gt;prepare("SELECT id FROM users WHERE username = ?");
          $stmt_id-&gt;bindParam(1, $username);
  
          $user_id = $stmt_id-&gt;execute();
          echo $user_id;
  
          $id_num_rows = $stmt_id-&gt;rowCount();
          if ($id_num_rows == 0) {
              echo 'You have entered a wrong password';
          }else if($id_num_rows == 1){
  
              $_SESSION['user_id'] = $user_id;
              print_r($_SESSION);
          }
      } else {
          echo("Please enter a username and password.");
      }
  }
  }
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;header&gt;
  
  &lt;/header&gt;
  &lt;body&gt;
  &lt;form action ="&lt;?php echo $current_file;?&gt;" method="post"&gt;
  &lt;div class='field'&gt;
      &lt;label for="username"&gt;Username: &lt;/label&gt;&lt;input type='text'   
                                               name='username'/&gt;&lt;br&gt;
  &lt;/div&gt;
  
  &lt;div class='field'&gt;
      &lt;label for ="password"&gt;Password: &lt;/label&gt;&lt;input type='password' 
                                                name='password'/&gt;
  &lt;/div&gt;
  
  &lt;div class='field'&gt;
      &lt;label for='remember'&gt;
          &lt;input type='checkbox' name="remember" id="remember"/&gt; Remember me
      &lt;/label&gt;
  &lt;/div&gt;
  &lt;input type='submit' value='Log in'/&gt;
  
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;And here is the code from core.inc.php
  
  &lt;?php
  session_start();
  require 'connect.inc.php';
  
  ob_start();
  $current_file = $_SERVER['SCRIPT_NAME'];
  @$http_referer = $_SERVER['HTTP_REFERER'];
  
  function loggedin(){
      if(isset($_SESSION['user_id']) &amp;&amp; !empty($_SESSION['user_id'])) {
          return true;
      }else{
          return false;
      }
  }
  
  ?&gt;
  
  &lt;Core.inc.php uses connect.inc.php which is added below:
  &lt;?php
  try {
  $db = new PDO('mysql:host=localhost;dbname=goal;charset=utf8','root','');
  var_dump($db);
  echo 'connected';
  }
  catch(Exception $e){
  echo 'Error 1 has occured';
  }
  ?&gt;
  </code></pre>