title: How do I use session variables within a SQL query?
body: <p>Here is my relevant code:</p>
  
  <pre><code>&lt;?php
   require("common.php");
  
   $userID = $_SESSION['user']['id'];
  
  echo $userID;
  if(!empty($_POST)) 
  { 
      if(empty($_POST['bio'])) 
          { 
              die("Please enter your Bio."); 
          }
  
      if(empty($_POST['location'])) 
          { 
              die("Please enter your location");      
          }  
  
  
      $query = 'UPDATE users
                SET usertype = 1
                WHERE id="$userID"';
  
  
      $query_params = array( 
          ':bio' =&gt; $_POST['bio'],
          ':location' =&gt; $_POST['location'], 
      ); 
  
      try 
      { 
          $stmt = $db-&gt;prepare($query); 
          $result = $stmt-&gt;execute(); 
      } 
      catch(PDOException $ex) 
      {   
          die("Failed to run query: " . $ex-&gt;getMessage()); 
      }
  
      // header("Location: myprofile.php");
  } 
  ?&gt; 
  </code></pre>
  
  <p>I'm trying to update the field usertype to 1 on submission of a form, where the id matches that of the current session, as set in the variable $userID. When the code runs, it provides no errors, but utilizing a PHP variable inside of the query doesn't seem to work, the field doesn't update.</p>
  
  <p>I've tried different quotes, and I can access the variable all throughout the multiple if statements, but not within the query. Also, I'm using PDO for this.  Any help is appreciated!</p>