title: Jquery Ajax and PHP form submission
body: <p>I've been working on a login form, that uses Jquery and Ajax to submit to a PHP file that processes the request then sends back a response. I think that somewhere, somehow the PHP script may be incorrect, because the form always comes back true allowing the person to login even when I purposely feed an incorrect password.</p>
  
  <p>Here is the html code:</p>
  
  <pre><code>    &lt;div id="login"&gt;
      &lt;span class="error"&gt;Uh oh! Something went wrong please try again!&lt;/span&gt;
      &lt;span class="success"&gt;Congrats! You've been logged in, redirecting you to your homepage&lt;/span&gt;
      &lt;form action="process/core/login.php" method="post"&gt;
      &lt;p&gt;Email: &lt;input type="text" name="email" &lt;?php if($_POST['email'] != '') { echo 'value="'. $_POST['email'] .'"'; }?&gt; /&gt;&lt;/p&gt;
      &lt;p&gt;Password: &lt;input type="password" name="pword" /&gt;&lt;/p&gt;
      &lt;p&gt;&lt;input type="submit" value="Login" id="login-btn" /&gt;&lt;/p&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  function redirect(){
      window.location = "home.php"
  }
  
  $("#login-btn").click(function(){
      $.ajax({
          type:       "post",                                     // type of post
          url:        "process/core/login.php",                   // submitting file
          data:       $("form").serialize(),                      // data to submit
          success: function() {
              $(".success").show("slow");                         // sucess function
              setTimeout('redirect()', 3000);
          },      
          error: function() {
              $('.error').show("slow");                           // error function
          }
      });
  return false;
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is the PHP script:</p>
  
  <pre><code>&lt;?php
  session_start();
  
  require '../../lib/core/connect.php';
  
  if(!empty($_POST['email']) &amp;&amp; !empty($_POST['pword'])) {
  
      $userInfo = mysql_query("SELECT * FROM users WHERE email = '". mysql_real_escape_string($_POST['email']) ."'");
      $userInfo = mysql_fetch_assoc($userInfo);
  
      if($_POST['email'] == $userInfo['email'] &amp;&amp; md5($_POST['pword']) == $userInfo['pword']) {
  
          if($userInfo['active'] == 1) {
  
              $_SESSION['AuthEmail']=$userInfo['email'];
              $_SESSION['AuthUid']=$userInfo['uid'];
              $_SESSION['AuthName']=$userInfo['fname'] . ' ' . $userInfo['lname'];
              $_SESSION['AuthActive']=$userInfo['active'];
              $_SESSION['AuthType']=$userInfo['type'];
  
              return true;
              print 'success';
          } else {
              return false;
              print 'fail not active';
          }
      } else {
          return false;
          print 'Email and or password didn\'t match';
      }
  
  } else {
      return false;   
      print 'Didn\'t enter one of the required values';
  }
  ?&gt;
  </code></pre>
  
  <p>Somewhere I have an error, I even changed all of the PHP script values to return false and somehow the success message in the ajax still fired successfully. Any help would be greatly appreciated, I've searched the entire forum finding related topics but found nothing that got real in depth with errors.</p>
  
  <p>Thanks</p>