I'm trying to prevent sql injection by binding parameters but when I convert my code to binded parameters, the mysqli_num_rows no longer works.
I have a simple email authentication that I want to check against the database for duplicate rows:
Below my code :
$checkDup = "SELECT Email FROM users WHERE Email='{$_POST['Email']}'";
$resultDup = mysqli_query($db,$checkDup);
//If not 0 duplicates (another one exists) create an error alert
if(!mysqli_num_rows($resultDup) == 0){
echo '<script language="javascript">
alert("Email Already Exists");
window.location.href = "Sign Up.php";
</script>';
unset($_POST);
}
After binding it -
Its Not right type error i got :
$checkDup = $db->prepare("SELECT Email FROM users WHERE Email= ?");
$checkDup->bind_param("s", $_POST['Email']);
//If not 0 duplicates (another one exists) create an error alert
if(!mysqli_num_rows($checkDup->execute()) == 0){
echo '<script language="javascript">
alert("Email Already Exists");
window.location.href = "Sign Up.php";
</script>';
unset($_POST);
}