2021年4月3日星期六

Stop the PHP form from clear/empty when email is already exists in databases

I tried to create a sign up form where I need to validate if the email is already exists in the database.

The code runs fine and can detect if the email is already exists in the database. The problem is it will clear all the form when it detects if email exists. Is there any way to not clear all the forms fields? Any help is appreciate.

  1. Here is the code for the form:
    <div class="form-group col-md-6">      <input name="email" title="Email pattren required" type="email" class="form-control input-fields" placeholder="Email Address" required id="email">      <span class="text-danger" id="Semail"></span>      </div>
  1. Here is code for email validation with the database.
if (isset($_POST['submit'])) {    $email = $_POST['email'];    $data = mysqli_query($sql_con, "select stdemail from students");    while ($row = mysqli_fetch_array($data)) {      $emaildb = $row['stdemail'];      if ($emaildb == $email) {        echo "<script>document.getElementById('Semail').innerHTML = '** Email already exist'; </script>";        exit();      }    }
https://stackoverflow.com/questions/66937671/stop-the-php-form-from-clear-empty-when-email-is-already-exists-in-databases April 04, 2021 at 11:03AM

没有评论:

发表评论