php - What am I doing wrong in checking if the mail already exist in MySQLI?


So, I got a code to check if the mail is already registrated in the users database.. But when I try to register using the same mail as registrated, it don't trigger the code. I tried to print the result and I used the code as IsValidUser("themail"); and it returned 1. But still it wont trigger the registration code.. Here's how I check it;

if(IsValidUser($reg_email) == 1) {
            $result = '<script>var iframe = document.createElement("IFRAME");iframe.setAttribute("src", "data:text/plain,");document.documentElement.appendChild(iframe);window.frames[0].window.alert("Error\nThis mail adress are already registrated.");iframe.parentNode.removeChild(iframe);</script>';

and here's the function;

function IsValidUser($mail) {
global $conn;
$sql = "SELECT * FROM users WHERE mail = '$mail'";
$result = mysqli_query($conn, $sql);
    die("Error description: " . mysqli_error($conn));
if(mysqli_num_rows($result) > 0)
    return 1;
    return 0;



I fixed it by placing the other if's under

else {
     if(..) {}

People are also looking for solutions to the problem: javascript - multiple comma seperate value compare using JS


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.