title: Php pdo SELECT statment not returning a value that i need
body: <p>I have a select statement that returns a user id:</p>
  
  <pre><code>        $stmt = $dbh-&gt;prepare("SELECT user_id FROM users WHERE username = '" . $user_name . "'");   
          $stmt-&gt;execute();
          $row = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
  
          $user_id = $row['user_id'];
  </code></pre>
  
  <p>This is working fine but when i call a function thats supposed to return the friend id: (The select statement)</p>
  
  <pre><code>function get_friend($friend_username){
  
  #create the PDO object 
  /**
   * Used to instanciate the host of the server
   * @var string
   */
      $hostname = 'localhost';
              /**
   * Used to instanciate the username to connect to the server
   * @var string
   */
      $username = 'ODBC';
              /**
   * Used to instanciate the password to connect to the server
   * @var string
   */
      $pass = "";
              /**
   * Used to instanciate the database name
   * @var string
   */
      $db_name = 'bloggie_db';
      try{
          $dbh = new PDO("mysql:host=$hostname;dbname=$db_name" , $username, $pass);
  
          #set PDO error mode to exception 
          $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          $stmt = $dbh-&gt;prepare("SELECT user_id FROM users WHERE username = '" . $friend_username . "'"); 
          $stmt-&gt;execute();
          $row = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
  
          $friend_id = $row['user_id'];   
          return $friend_id;
      }catch(PDOException $e){
          $e-&gt;getTrace();
      }
      $dbh = null;
  } //The whole get friend function
  </code></pre>
  
  <p>The function call:</p>
  
  <pre><code>        $friend_id = $this-&gt;get_friend($friend_user_name);
  </code></pre>
  
  <p>This does not return anything but if i replace $friend_user_name with the value thats in the database 'testing@bloggie.com', then the $friend_id is returned. Why is it that when i use a variable it doesnt return but when i use an actual value it does return.</p>