I have this PHP code, which registers a user, all form validation is done by jQuery and request is sent by ajax to this PHP page. Everything is working fine except its not checking if email and mobile is already registered.
<pre><?php
require('db_connection.php');
$error= "";
if($_SERVER['REQUEST_METHOD']=="POST"){
$name=$_POST['name'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$password=$_POST['password'];
$hashed_password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$sql = "SELECT `user_email`,`user_mobile` FROM `users` where `user_email` = ? OR `user_mobile` = ? LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss",$email,$mobile);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows() > 0){
$stmt->fetch();
if($email==isset($row['user_email'])){
echo "email exists";
}
if($mobile==isset($row['user_mobile'])){
echo "mobile exists";
}
}else{
$stmt= $conn->prepare("INSERT INTO `users`(`user_name`, `user_email`, `user_mobile`, `user_password`) values (?, ?, ?, ?)");
$stmt->bind_param("ssss",$name,$email,$mobile,$hashed_password);
$stmt->execute();
echo "successfull";
}
$stmt->close();
}
$conn->close();
?>
What I have tried:
from my observation the problem is somewhere I'm fetching the rows, because the registration is happening with different email and mobile.