Jump to content

Recommended Posts

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 :D

 

post-179600-0-22711500-1441059974_thumb.png

 

 

 

 

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.

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 by KillZoneZ

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.
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.