PHP If statements not working
<p>This is my code:      </p>

<pre><code>    if ($username == "" || $pass == "" || $emailad==""|| $fname=="")
{  
    $msg = "Not all fields were entered"; 
}else
{
    if(uniqueUser($username,$emailad))
    {
        $msg="The username or email already exists";
    }else
    { 
        insertIntoDB($fname,$emailad,$username,$pass);
        $msg="The user has been inserted";

    }

}
    echo $msg;
</code></pre>

<p>this will be used to insert a new user into my db. However my problem is if I am to add a non existing user into it, the program will tell me that the username already exists BUT it will insert the new account if its not in the database. Therefore the program works fine in terms of insertion depending upon if the user exists in the database or not. The problem is the message display for me because I will never know if the user is already in the database or not since no matter how I rewrite this piece of code, a non existent user insertion will result in the wrong message being displayed. This is because the code will run the if statements, insert the new user....and run again displaying the message that it already exists. Could anybody explain why this happens?</p>

<p>Unique user function:</p>

<pre><code>function uniqueUser($usern,$eml)
{
$query = "SELECT S.username,S.email FROM tbl_user S WHERE S.username='$usern' OR        S.email='$eml'";
return mysql_num_rows(queryMysql($query));
}
</code></pre>
