KillZoneZ Posted August 31, 2015 Share Posted August 31, 2015 Hello, For some reason this if condition is returning true even though it is false, that is, instead of echoing the sentence should have gone forward because it was inputed correctly on the form. Here is the code: if($BetaKey != $result=mysqli_query($conn,"SELECT BetaKey FROM betakey WHERE BetaKey = '$BetaKey'")) { echo "• Either that Beta Key has already been used or isnt for the specified e-mail."; } Form used in the php code's code: <form method="post" action="RegisterCheckUp.php"> <span id="UsernameLabel">Username:<span class="required">*</span></span> <br> <input type="text" maxlength="16" id="Username" name="username" placeholder="Username" value="" required="required"/> <br> <span id="PasswordLabel">Password:<span class="required">*</span></span> <br> <input maxlength="16" type="password" id="Password" name="password" placeholder="Password" value="" required="required"/> <br> <span id="PasswordAgainLabel">Repeat Password:<span class="required">*</span></span> <br> <input type="password" id="PasswordAgain" name="passwordagain" placeholder="Password(Again)" value="" required="required"/> <br> <span id="E-MailLabel">E-Mail:<span class="required">*</span></span> <br> <input type="email" id="E-Mail" name="email" placeholder="E-Mail" value="" required="required"/> <br> <span id="BetaKeyLabel">Beta Key:<span class="required">*</span></span> <br> <input id="BetaKey" required="required" name="betakey" type="text" maxlength="10" placeholder="Your Beta Key" /> <span id="Warning">All fields are required</span> <input name="submit" type="submit" value="Sign Up" id="SignUpButton"/> </form> In the attached files there is an image of the database table. Thank You Quote Link to comment https://forums.phpfreaks.com/topic/298002-if-statement-returning-true-for-unknown-reason/ Share on other sites More sharing options...
requinix Posted August 31, 2015 Share Posted August 31, 2015 mysqli_query will return a resource representing a resultset which you can use to access the data returned from the query. It does not return actual values. You have to use one of the assorted fetch functions to get those. Quote Link to comment https://forums.phpfreaks.com/topic/298002-if-statement-returning-true-for-unknown-reason/#findComment-1520039 Share on other sites More sharing options...
KillZoneZ Posted August 31, 2015 Author Share Posted August 31, 2015 (edited) mysqli_query will return a resource representing a resultset which you can use to access the data returned from the query. It does not return actual values. You have to use one of the assorted fetch functions to get those. Im not quite catching it sorry, could you give me an example? @Edit Been thinking on other ways to check if a value already exists in the database and thought this: Could i use mysqli_num_rows to check how many rows the result set has and if it was bigger than 0 it would mean that there is already a field with the same value on the database. Would that work? Thanks for the quick answer btw Edited August 31, 2015 by KillZoneZ Quote Link to comment https://forums.phpfreaks.com/topic/298002-if-statement-returning-true-for-unknown-reason/#findComment-1520041 Share on other sites More sharing options...
requinix Posted August 31, 2015 Share Posted August 31, 2015 Been thinking on other ways to check if a value already exists in the database and thought this: Could i use mysqli_num_rows to check how many rows the result set has and if it was bigger than 0 it would mean that there is already a field with the same value on the database. Would that work?Yup, that would work too. If the BetaKey isn't unique (and isn't supposed to be) then you should add a LIMIT 1 to the query so that it stops searching for matching rows after it finds the first one. Quote Link to comment https://forums.phpfreaks.com/topic/298002-if-statement-returning-true-for-unknown-reason/#findComment-1520042 Share on other sites More sharing options...
KillZoneZ Posted August 31, 2015 Author Share Posted August 31, 2015 Yup, that would work too. If the BetaKey isn't unique (and isn't supposed to be) then you should add a LIMIT 1 to the query so that it stops searching for matching rows after it finds the first one. Yup Thank You Quote Link to comment https://forums.phpfreaks.com/topic/298002-if-statement-returning-true-for-unknown-reason/#findComment-1520043 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.