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 {
 // ....
}

SOLVED: in the sql need OR not AND :D

$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.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.