title: Debugging a MYSQL syntax error
body: <p>The following is a "forgot password" script I have on my site.   I have one MYSQL table where I store the email addresses of users.  It is called 'members' and has 2 columns: 'user' (users' email addresses) and 'pass' (their passwords).  </p>
  
  <p>The email address adamjwilkins1604@gmail.com exists in the members table. When I input this email address in the forgot password form, I get this error.  I am having a lot of trouble debugging this.</p>
  
  <pre><code>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com' at line 1
  </code></pre>
  
  <p>Forgot password script:</p>
  
  <pre><code>&lt;?php // forgot_password.php
  include_once 'header.php';
  
  if (isset($_POST['submitted']))
      { // Handle the form.
      if (empty($_POST['email'])) 
          {
          $uid = FALSE;
          echo 'You forgot to enter your registered email address!';    
          }
          else 
              {
              // Check for the existence of the inputted email address.
              $email = trim(sanitizeString($_POST['email']));
              $result = queryMysql("SELECT user FROM members WHERE user='$email'");
                  if (mysql_num_rows($result) == 1)
                      {
                      // Retrieve the user's email address
                      list($uid) = mysql_fetch_array ($result, MYSQL_NUM);
                      }
                      else 
                          {
                          echo '&lt;p&gt;&lt;font color="red" size="+1"&gt;The submitted email address does not match those on file!&lt;/font&gt;&lt;/p&gt;';
                          $uid = FALSE;
                          }
              }
  
          if ($uid)
              {
              $p = substr(md5(uniqid(rand(),1)),3,10);
              $result = queryMysql("UPDATE members SET pass=SHA('$p') WHERE user = $uid");
              if (mysql_affected_rows() == 1) 
                  {
                  // If it ran OK, send an email.
                  $email = trim(sanitizeString($_POST['email']));
                  $body = "Your password has been temporarily changed to '$p'. Please log in using this password and your username.";
                  mail ($email, 'Your temporary password.', $body, 'From: admin@mywebsite.com');
                  echo '&lt;h3&gt;Your password has been changed. You will receive the new, temporary password at the email address with which you registered. Once you have logged in with this password, you may change it by clicking on the "change password" link.&lt;/h3&gt;';
                  mysql_close(); // Close the database connection.
                  }
                  else
                      {
                      // If it did not run OK.
                      echo '&lt;p&gt;&lt;font color="red" size="+1"&gt;Your password could not be changed due to a system error. We apologize for any inconvenience.&lt;/font&gt;&lt;/p&gt;';
                      }
              }
                  else // Failed the validation test.
                      {
                      echo '&lt;p&gt;&lt;font color="red" size="+1"&gt;Please try again.&lt;/font&gt;&lt;/p&gt;';
                      }
      } // End of the main Submit conditional.
  ?&gt;
  
  &lt;h1&gt;Reset Your Password&lt;/h1&gt;
  &lt;p&gt;Enter your email address below and your password will be reset.&lt;/p&gt;
  &lt;form action="forgot_password.php" method="post"&gt;
  &lt;fieldset&gt;
  &lt;p&gt;&lt;b&gt;Your registered email address:&lt;/b&gt; &lt;input type="text" name="email" size="20" maxlength="40" value="&lt;?php if (isset($_POST['email'])) echo $_POST['email']; ?&gt;" /&gt;&lt;/p&gt;
  &lt;/fieldset&gt;
  &lt;div align="center"&gt;&lt;input type="submit" name="submit" value="Reset My Password" /&gt;&lt;/div&gt;
  &lt;input type="hidden" name="submitted" value="TRUE" /&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>