I am trying to check the email address if it already exists in the table, but this does not work.
Here is my code:
<html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $('#Submit').click(function() { var emailVal = $('#email').val(); </script> </head> <body> <form id="form1" name="form1" method="post" action="view.php"> <p> <input type="text" name="email" id="email" /> </p> <p> <input type="submit" name="Submit" id="Submit" value="Submit" /> </p> </form> </body></html>
When you click the submit button, it must first perform a check using jQuery and invoke the checkemail.php file, as shown below:
<?php include("../includes/db.php"); $sql = "SELECT email FROM lf_clients WHERE email = " .$_POST['email']; $select = mysqli_query($con, $sql); $row = mysqli_fetch_assoc($select); if (mysqli_num_rows > 0) { echo "The email already exists."; } ?>
However, when I click the submit button, it goes to view.php instead of checkemail.php. Before redirecting to view.php, it must first check if email exists or not. If the message already exists, it should not be redirected to view.php.
source share