Jump to content

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given


KillZoneZ

Recommended Posts

My code is returning Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given and i cant find out why :( Please help

$CheckUsername = mysqli_query($conn,"SELECT Username FROM users WHERE Username='$Username'");
            $CheckEmail = mysqli_query($conn,"SELECT E-Mail FROM users WHERE E-Mail='$Email'");
            $CheckBetaKey = mysqli_query($conn,"SELECT BetaKey FROM betakey WHERE BetaKey='$BetaKey' AND E-Mail='$Email'");
            
            if ($Password != $PasswordAgain || ($CheckUsername != FALSE) || ($CheckEmail != FALSE) || (mysqli_num_rows($CheckBetaKey) != 1))
                {
                    if ($Password != $PasswordAgain) {
                        echo "• Passwords did not match.";
                    }
                    else {}
                    if ($CheckUsername != FALSE) {
                        echo "• That Username has already been taken.";
                    }
                    else{}
                    if ($CheckEmail != FALSE) {
                        echo "• That E-Mail has already been registered.";
                    }
                    else{}
                    if (mysqli_num_rows($CheckBetaKey) != 1) {
                        echo "• Either that Beta Key has already been used or isn't for the specified e-mail address.";
                    }
                    else{}
                }
            else {
                $InsertUser = mysqli_query($conn,"INSERT INTO users (Username,Password,E-Mail,BetaKey) VALUES ('$Username','$Password','$E-Mail','$BetaKey')");
                $DeleteBetaKey = mysqli_query($conn,"DELETE * FROM betakey WHERE BetaKey='$BetaKey' AND Mail='$Email'");
                header ("Location: Index.php");
            }

Also, the second condition:

if ($CheckUsername != FALSE) {
               echo "• That Username has already been taken.";
}
               else{}

is returning true even though there is no User in the database.

 

The same happens with the last one.

if (mysqli_num_rows($CheckBetaKey) != 1) {
                        echo "• Either that Beta Key has already been used or isn't for the specified e-mail address.";
                    }
                    else{}
                }
Edited by KillZoneZ
Link to comment
Share on other sites

...is returning true even though there is no User in the database.

 

 

this is exactly the same as what your last thread was about. if the query runs without any errors, the mysqli_query() statement returns a result resource that you use to access the result of the query (fetch data, check the number of rows...) not matching a row is not an error, it's an empty result set (no rows.) the mysqii_query() statement returns a false value only if the query failed due to an error of some kind, usually something wrong with the sql statement, the database, or the database connection.

 

The same happens with the last one.

 

 

the php error message you are getting about the parameter you are passing to the mysqli_num_rows() function not being of an expected value supersedes the value the mysqli_num_rows() function is designed to return. if you are passing garbage into the function, you get garbage out.

 

your code needs to test if each query runs or fails before you can use the result from the query. this is not just a debugging step when you have a problem. you must always do this. if the query has failed, you need to use the error information from php/mysql to find out why and fix the problem and you should stop the code from running any further statements that are dependent on the result of the query, since there isn't any. the error you are getting in this thread is a follow-on error due to a problem earlier in the code. it's not where the problem is at.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.