title: Error using ajax to check email from database
body: <p>I've read the answers from several users here, and my intention is to check if the email is already on the DB.</p>
  
  <p>So my code is the following </p>
  
  <pre><code>**HTML CODE**
  &lt;div class="form-group"&gt;
                    &lt;div class="col-sm-12"&gt;
                      &lt;div class="input-group"&gt;
                        &lt;span class="input-group-addon"&gt;&lt;span class="glyphicon glyphicon-user"&gt;&lt;/span&gt;&lt;/span&gt;
                        &lt;input id="fnam" name="firstname" class="profile-input form-control" type="text" placeholder="First Name" autocomplete="off" maxlength="25" required /&gt;
  
                       &lt;!-- &lt;input id="fullname" name="fullname" class="form-control" placeholder="Full Name" required="" type="text"&gt;--&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/fieldset&gt;
  
              &lt;fieldset&gt;
              &lt;!-- Prepended text Last Name--&gt;
                  &lt;div class="form-group"&gt;
                    &lt;div class="col-sm-12"&gt;
                      &lt;div class="input-group"&gt;
                        &lt;span class="input-group-addon"&gt;&lt;span class="glyphicon glyphicon-user"&gt;&lt;/span&gt;&lt;/span&gt;
                        &lt;input id="lastname" name="lastname" class="profile-input form-control" type="text" placeholder="Last Name" autocomplete="off" maxlength="25" required /&gt;
               &lt;!-- &lt;input id="fullname" name="fullname" class="form-control" placeholder="Full Name" required="" type="text"&gt;--&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/fieldset&gt;
  
              &lt;fieldset&gt;
                  &lt;!-- Prepended text Email--&gt;
                  &lt;div class="form-group"&gt;
                    &lt;div class="col-sm-12"&gt;
                      &lt;div class="input-group"&gt;
                        &lt;span class="input-group-addon"&gt;&lt;span class="glyphicon glyphicon-envelope"&gt;&lt;/span&gt;&lt;/span&gt;
                        &lt;input id="email" name="email"  class="profile-input form-control" type="email" placeholder="Email" autocomplete="off" maxlength="50"  required/&gt;
              &lt;!-- &lt;input id="email" name="email" class="form-control" placeholder="Email" required="" type="text"&gt;--&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>JS/ AJAX</p>
  
  <pre><code> function chemail(inputText) {
   var email1 = $("#email").val();
   var x = document.forms["myappForm"]["email"].value;
   var datastring = '$email='+ x; // get data in the form manual
  
  
  
   //var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
  
  
      var atpos = x.indexOf("@");
      var dotpos = x.lastIndexOf("."); 
  
  // if(inputText.value.match(mailformat)){
  
    if (atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=x.length) {
  
  var msgp="Invalid Email. Ex: abc@ggggg.com";
      document.getElementById("msgreturn").style.color= "red";
       document.getElementById("msgreturn").innerHTML = msgp;
        document.getElementById("lem").style.color= "red";
  document.myappForm.email.focus();  
  
  
  return false;  
  }  
  
  
  else  
  {  
   document.myappForm.email.focus();  
   var msgp="Email verified";
      document.getElementById("msgreturn").style.color= "green";
       document.getElementById("msgreturn").innerHTML = msgp;
        document.getElementById("lem").style.color= "green";
  
  return true;  
  
  
  $("span.loading").html("&lt;img src='images/ajax_fb_loader.gif'&gt;");
          $("span.validation").html("");
          var datastring = '&amp;email='+ x;
          $.ajax({
                      type: "POST", // type
                      url: "check_email.php", // request file the 'check_email.php'
                      data: datastring, // post the data
                      success: function(responseText) { // get the response
                          if(responseText == 1) { // if the response is 1
                              $("span.email_val").html("&lt;img src='images/invalid.png'&gt; Email are already exist.");
                              $("span.loading").html("");
                          } else { // else blank response
                              if(responseText == "") {
                                  $("span.loading").html("&lt;img src='images/correct.png'&gt; You are registred.");
                                  $("span.validation").html("");
                                  $("form input[type='text']").val(''); // optional: empty the field after registration
                              }
                          }
                      }
                                      } 
   }
  </code></pre>
  
  <p>and the check_email.php</p>
  
  <pre><code>&lt;?php require_once("../../php_includes/dbconnect.php"); 
  
  $email = $_POST['x']; 
  $query = mysql_query("SELECT 'email' FROM 'members' WHERE 'email' = '$email'"); 
  if(mysql_num_rows($query) == 1) {  echo '1'; } else {  echo '1'; } 
  
  ?&gt;
  </code></pre>
  
  <p>So the sources are all working, I've set some alerts inside of ajax but it didn't worked, can you please tell me where am I making the mistake , I'm following the example from other users from this site, however can't reach a solution.</p>