title: MySQL PHP Query Invalid - Can't find column
body: <p><strong>UPDATE:
  The suggestion of the '' worked around $username. Thanks! But now, the table isn't actually getting updated from the $lastLoginTime.</strong></p>
  
  <p>I have some problem with my query that I can't seem to figure out for the life of me and I am at a halt.</p>
  
  <p>Let's take a look at the code. </p>
  
  <pre><code>function checkTOS($preusergrab){
  include("includes/opendb.php");
  
  $query = "SELECT * FROM users WHERE username='".$preusergrab."'";
  $result = mysql_query($query) or die(mysql_error());
  
  while($row = mysql_fetch_assoc($result)){
      $resultset[] = $row;
      $TOS = $row['acceptTOS'];
      }
  
  mysql_free_result($result);
  
   if($TOS == 1){
   // return to processor
  
      $lastLoginTime = time();
  
      $query = mysql_query("UPDATE users 
                      SET lastLoginTime = '$lastLoginTime' 
                          WHERE username = $username");
  
                          if (!$query) {
  
               die('&lt;br&gt;Invalid query: ' . mysql_error());
              }
  
  
   }elseif($TOS == 0 || $TOS = ''){
      header("Location: http://partner.domain.com/terms.php?action=show");
      die();
  }else{
  echo 'Internal Application Error:';
  echo 'Value unrecognizable.';
  echo '&lt;br&gt;Please alert someone at user@domain.com';
  die();
  }
   }
  </code></pre>
  
  <p>Now, where the problem comes in is at this section:</p>
  
  <pre><code>    $lastLoginTime = time();
  
      $query = mysql_query("UPDATE users 
                      SET lastLoginTime = '$lastLoginTime' 
                          WHERE username = $username");
  
                          if (!$query) {
  
               die('&lt;br&gt;Invalid query: ' . mysql_error());
              }
  </code></pre>
  
  <p>It says the following:</p>
  
  <pre><code>   Invalid query: Unknown column 'theuser' in 'where clause'
  </code></pre>
  
  <p>In this case, 'theuser' is the user that $preusergrab is representing.</p>
  
  <p>In my table, the username is the primary key, row 0.</p>
  
  <p>What could possibly be invalid if I know the row is there and everything else works?</p>