title: Checking if a PHP form is valid for the purpose of locking out a user after 3 attempts
body: <p>I have a php login form with some authentication and validation. The particular script I have so far which I want to run is as follows:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var login_attempts=3;
  function check_form()
   {
      //This is where I want the code to check if the form is valid and will be submitted
   {
     alert("SuccessFully Logged In");
     //Not sure if I need this as the form contains PHP so if the credentials are correct then tehy go to another page
   }
  
    else
        {
         if(login_attempts==0)
         {
         alert("No Login Attempts Available");
         }
  
      else
        {
        login_attempts=login_attempts-1;
        alert("Login Failed Now Only "+login_attempts+" Login Attempts Available");
  
      if(login_attempts==0)
         {
          document.getElementById("name").disabled=true;
          document.getElementById("pass").disabled=true;
          document.getElementById("form1").disabled=true;
    }
   }
  }
  
  return false;
  }   
  &lt;/script&gt;
  </code></pre>
  
  <p>The reason I want this, is so that after a user has attempted to login 3 times I want an alert box to display a message and also stop the user from entering anything in the box. I don't actually want to lock the account from the DB end as the users are authenticating on information other than a username and password.</p>
  
  <p>I am quite novice when it comes to Js so sorry if I missed anything out</p>
  
  <p>Edit: PHP login code</p>
  
  <pre><code>&lt;?php
  if($_POST)
    {
      include 'config.php';
  $ref=$_POST['ref'];
  $fullname=$_POST['fullname'];
  $postcode=$_POST['postcode'];
  $dob=$_POST['dob'];
  $email=$_POST['email'];
  
  $sUser=mysqli_real_escape_string($conn,$orielref);
  $sPass=mysqli_real_escape_string($conn,$fullname);
  $sPostcode=mysqli_real_escape_string($conn,$postcode);
  $sDob=mysqli_real_escape_string($conn,$dob);
  $sEmail=mysqli_real_escape_string($conn,$email);
  $query="SELECT * From customers where ref_number='$sUser' and full_name='$sPass' and post_code='$sPostcode' and date_of_birth='$sDob' and email_address='$sEmail'";
  $result=mysqli_query($conn,$query);
  if(mysqli_num_rows($result)==1)
  {   $row = $result-&gt;fetch_array(MYSQLI_ASSOC);
      session_start();
      $_SESSION['id'] = $row['id'];
      $_SESSION['ref_number'] = $row['ref_number'];
      header('location:index.php');
  }
  }
  
  ?&gt;
  </code></pre>