0

How can i check if username and email exists i have this code but its only checking the email not the username...

$sql = "SELECT `Email`, `UserUsername` FROM `users` WHERE `UserUsername`='".$user."' AND `Email`='".$email."'";
$result = $conn->query($sql);

if($result->num_rows >= 1) {
    echo "Email or Username already exist, try something else.";
} else {
 // ....
}
3
Contributors
3
Replies
16
Views
1 Year
Discussion Span
Last Post by saheedriswan
0
$sql = "SELECT `Email`, `UserUsername` FROM `users` WHERE `UserUsername`='".$user."' OR `Email`='".$email."'";
$result = $conn->query($sql);
if($result->num_rows >= 1) {
    echo "Email or Username already exist, try something else.";
} else {
 // ....
}

better test for email and username seperately to instruct the user specifically by nested if condition.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.