KillZoneZ Posted September 2, 2015 Share Posted September 2, 2015 (edited) 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 September 2, 2015 by KillZoneZ Quote Link to comment Share on other sites More sharing options...
Barand Posted September 2, 2015 Share Posted September 2, 2015 Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given That must be the most frequently asked question in the forums. I am surprised that the search you made before posting did not find any results Quote Link to comment Share on other sites More sharing options...
KillZoneZ Posted September 2, 2015 Author Share Posted September 2, 2015 It did actually, but non of them resembled to something similar to my code, that's why i thought i would ask. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 2, 2015 Share Posted September 2, 2015 http://forums.phpfreaks.com/topic/298020-expects-parameter-1-to-be-mysqli-result/?do=findComment&comment=1520121 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 2, 2015 Share Posted September 2, 2015 ...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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.