0

I need to check email exist in the table if already exist show alert without refreshing the page?

 <input class="form-control" type="email"  name="email" id="email" required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" onblur="javascript:checkInput();" placeholder="Email address" >

 <button type="submit" name="submit" id="submit" onClick="reg()" class="btn btn-primary btn-block"> Create Account  </button>
<script>
        ///////////////////////////////// Email Validate Function ////////////////////////////////////////
        function validateEmail($email) {
          var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
          return emailReg.test( $email );
        }
        ///////////////////////////////// Login User ////////////////////////////////////////
        function reg()
        {
            var email    =  $("#email").val();
            var password =  $("#password").val();
            
            if (email == null || email == "") 
            {
                $("#loginerrormsg").html("Please enter Valid Email");
                alert("Please enter Registered Email");
                $("#loginerrormsg").show();
                setTimeout(function(){ $("#loginerrormsg").hide();}, 3000);
            }
Dharman
  • 30,962
  • 25
  • 85
  • 135
Khurram
  • 13
  • 5
  • 1
    Does this answer your question? [Submit form without page reloading](https://stackoverflow.com/questions/2866063/submit-form-without-page-reloading) – GNassro Jul 18 '20 at 09:55

1 Answers1

0

You need to use JavaScript and AJAX to send a request to the server without reloading the page. PHP should then query your DB and return the response for further validation at client-side. It is NOT possible to query the database using raw JS.

biesior
  • 55,576
  • 10
  • 125
  • 182