I got this code from someone here from stack overflow I copied it and I tried it out but I doesn't work the way I want it to if I put an already existing email address from my database it gives an error saying email address already taken please choose another email. but when I submit an email address that is not in the database it still displays the same error how can this be fixed
<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">
$(document).ready(function(){ //newly added
$('#submit').click(function() {alert("Email already exists. Please choose a different email");
var emailVal = $('#email').val(); // assuming this is a input text field
$.post('checkemail.php', {'email' : emailVal}, function(data) {
if (data == 1)
{
$("#registration").submit();
}
else
{
return false;
}
});
});});
</script>
</head>
<body>
<form id="registration" name="registration" method="post" action="profile1.php">
<p>email
<input type="text" name="email" id="email" />
</p>
<p>
<input type="button" name="submit" id="submit" value="submit" />
</p>
</form>
</body>
</html>
and here is the php code
<?php
include("con.php");
$sql = "SELECT email FROM registered_d WHERE email = " .$_POST['email'];
$select = mysqli_query($con, $sql);
$row = mysqli_fetch_assoc($select);
if (mysqli_num_rows > 0) {
echo "0"; // email exists
}else{
echo "1"; // email doesn't exists
return;}
?>
can someone help me solve this