I Have written a query for validating the email ids to not accept the duplicate emails while inserting into database.But it is not working and inserting duplicate email ids into database.
if(isset($_POST['submit_user'])){
$email = $_POST['user_email'];
$check=mysqli_query($conn,"select * from users where user_email='$email'");
$checkrows=mysqli_num_rows($check);
if($checkrows>0) {
echo "Email Already exists";
} else {
if($_POST['password'] == $_POST['con_password']){
$date = date('Y-m-d h:i:s');
$ins_sql = "INSERT INTO users (first_name, last_name, user_email, user_password, user_gender, user_marital_status, user_phone_no, user_designation,user_address,user_date,user_role,username) VALUES ('$_POST[first_name]', '$_POST[last_name]', '$_POST[email]', '$_POST[password]', '$_POST[gender]', '$_POST[marital_status]', '$_POST[phone_no]', '$_POST[designation]', '$_POST[address]', '$date','$_POST[user_role]' , '$_POST[username]')";
$run_sql = mysqli_query($conn,$ins_sql);
}else {
$match = '<div class="alert alert-danger">Password doesn't match!</div>';
}
}