title: Checking for duplicate mysql data with bootstrap validator
body: <p>I created a signup form with the bootstrap validator and connected it to a MySQL database. I wish to prevent duplicate entries by checking for existing email data and returning a message through the bootstrap validator script. I am using the remote method but the problem is as soon as I start typing in the email field, I get the "Email has already been taken." message although the email may not already exist in the database or if it is only one alphabet typed. I also get data entries even when I have not submitted the form. I have searched online and realized most of the solutions exist for the jquery validation plugin but no the bootstrap validator. I need help, please. Here is my code:</p>
  
  <p><strong>signup.php</strong></p>
  
  <p>
      </p>
  
  <pre><code> &lt;div class="signup-form"&gt;
   &lt;h1&gt;Sign up for free!&lt;/h1&gt;&lt;br&gt;
  
   &lt;form id="form1" action="registration.php" class="loading-form" method="POST"&gt;
  
  &lt;div class="form-group"&gt;
    &lt;label for="name-input"&gt;Username&lt;/label&gt;
    &lt;input required type="text" name="username" class="form-control" id="username" maxlength="100"&gt;
  &lt;/div&gt;    
  
    &lt;label for="email-input"&gt;Email&lt;/label&gt;
    &lt;input required name="email" type="email" class="form-control" id="email" title="An email is required"&gt;
  &lt;/div&gt;
  
  &lt;p&gt;You accept our &lt;a href="pages/terms.php" style="color: #337ab7;"&gt;Terms &amp;amp; Conditions&lt;/a&gt; by creating your account.&lt;/p&gt;
  
  &lt;div class="form-group"&gt;
  &lt;!-- Do NOT use name="submit" or id="submit" for the Submit button --&gt;
  &lt;button type="submit" class="btn btn-success"&gt;Sign up&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
      </p>
  
  <pre><code>  &lt;script&gt;
    $(document).ready(function() {
    $('#form1').bootstrapValidator({
      // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
      feedbackIcons: {
          valid: 'glyphicon glyphicon-ok',
          invalid: 'glyphicon glyphicon-remove',
          validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
          username: {
              message: 'The username is not valid',
              validators: {
                  notEmpty: {
                      message: 'The username is required'
                  },
                  stringLength: {
                      min: 6,
                      max: 30,
                      message: 'The username must be more than 6 and less than 30 
          characters long'
                  },
                  regexp: {
                      regexp: /^[a-zA-Z-' ]+$/,
                      message: 'The username can only consist of alphabetical and number'
                  },
                  different: {
                      field: 'password',
                      message: 'The username and password cannot be the same as each other'
                  }
              }
          },
          email: {
              validators: {
                  notEmpty: {
                      message: 'The email address is required'
                  },
                  emailAddress: {
                      message: 'The email address is not a valid'
                  },
                  remote: {
                      message: 'The email address is already taken.',
                      url: "registration.php"
                  }
              }
          },
      }
  });
  });
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <p></p>
  
  <p><strong>registration.php</strong></p>
  
  <pre><code>&lt;?php   
  include ("connect.php");
  session_start();
  
  $username = $_POST['username'];
  $email = $_POST['email'];
  
  $username = mysqli_real_escape_string($con, $_POST['username']);
  $email = mysqli_real_escape_string($con, $_POST['email']);
  
  $query1 = "SELECT * FROM registration where (email='$email')";
  $check = mysqli_query($con, $query1);
  $checkrows=mysqli_num_rows($check);
  
  if($checkrows&gt;0) {
  echo json_encode(FALSE);
  }
  else
  {
  echo json_encode(TRUE);
  }
  
  //insert results from the form input
  $query = "INSERT INTO registration (username, email) VALUES('$username', '$email')";
  $result = mysqli_query($con, $query);
  $num1=mysqli_num_rows($result);
  $row = mysqli_fetch_assoc($result);
  
  ?&gt;
  </code></pre>