Reputation: 45
I have a form to register e-mails on my site. I am trying to create a check in PHP to first determine if the e-mail has already been registered in the DB before allowing the user to register it again.
The IF statement is not executing.... what have I done wrong? The else statement works fine.
Please note - the db.php file includes the connection settings $conn. The else statement is putting the e-mail addresses into the db.
<?php
include_once 'db.php';
$fullname = $_POST['signup_name_of_user'];
$email = $_POST['signup_email_of_user'];
mysqli_select_db('database');
if(isset($_POST['signup_email_of_user']))
{
$checkdata = "SELECT signup_email_of_user FROM database WHERE signup_email_of_user = '$email'";
$query = mysqli_query($conn, $checkdata);
if(mysqli_num_rows($query>0))
{
echo "E-mail Already Exists. You cannot register more than twice!";
exit();
}
else {
$sql = "INSERT INTO database (signup_name_of_user, signup_email_of_user) VALUES ('$fullname', '$email')";
mysqli_query($conn, $sql);
echo "You have been successfully registered";
}
}
?>
Upvotes: 1
Views: 335
Reputation: 6135
You just have a typo in your PHP script, change
if(mysqli_num_rows($query>0))
Into
if(mysqli_num_rows($query) > 0)
Upvotes: 3