If the database has the same phone number with new registered user, the register progress not completed, but at my code, the data still enter the database table with same phone number.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$name = $_POST['name'];
$no_hp = $_POST['no_hp'];
$email = $_POST['email'];
$password = $_POST['password'];
$password = password_hash($password, PASSWORD_DEFAULT);
require_once 'connect.php';
$sql = "INSERT INTO user(name,no_hp,email,password)VALUES('$name','$no_hp','$email','$password')";
$hpcheck = "SELECT * FROM user WHERE no_hp='$no_hp' LIMIT 1";
$result = mysqli_query($conn, $hpcheck);
if(mysqli_query($conn, $sql)){
if(mysqli_num_rows($result) > 0)
{
$result["success"] = "0";
$result["message"] = "Nomor hp telah digunakan!";
echo json_encode($result);
mysqli_close($conn);
}
else
{
$result["success"] = "1";
$result["message"] = "success";
echo json_encode($result);
mysqli_close($conn);
}
} else {
$result["success"] = "0";
$result["message"] = "errorss";
echo json_encode($result);
mysqli_close($conn);
}
}
?>