Jump to content

Code running before it shouldn't.


ChrisMartino

Recommended Posts

Hello there,

 

I have a problem where the following code is running the query before it should.

 

    private function isAccountRegistered($AccountUsername, $AccountEmail)
    {
        global $Class;

        if($Class['MySQL']->currentRows("SELECT * FROM xhost_accounts WHERE account_username = '".$Class['MySQL']->parseClientInput($AccountUsername)."'") == 1)
        {
            return USERNAME_REGISTERED;
        }
        else if($Class['MySQL']->currentRows("SELECT * FROM xhost_accounts WHERE account_email = '".$Class['MySQL']->parseClientInput($AccountEmail)."'") == 1)
        {
            return EMAIL_REGISTERED;
        }
    }
    
    public function createClientAccount($AccountUsername, $AccountPassword, $AccountEmail, $AccountRealname)
    {
        global $Class;

        if($this->isAccountRegistered($AccountUsername, $AccountEmail) == USERNAME_REGISTERED)
        {
            echo("<div class=\"warning\">Unfortunately this username is in use by another member!, please select another!.</div>");
        }
        else if($this->isAccountRegistered($AccountUsername, $AccountEmail) == EMAIL_REGISTERED)
        {
            echo("<div class=\"warning\">Unfortunately this email address is in use by another member!, please select another!.</div>");
        }
        else
        {
            if($Class['MySQL']->Query("INSERT INTO xhost_accounts (account_username, account_password, account_email, account_realname, account_regdate, account_regtime, account_level, account_balance, account_notifications) VALUES('".$Class['MySQL']->parseClientInput($AccountUsername)."', '".md5($Class['MySQL']->parseClientInput($AccountPassword))."', '".$Class['MySQL']->parseClientInput($AccountEmail)."', '".$Class['MySQL']->parseClientInput($AccountRealname)."', '".date("d/m/y")."', '".time()."', '0', '0.00', 'Enabled')"))
            {
                $Class['Core']->refresh('index.php');
            }
            else
            {
               echo("<div class=\"warning\">Unfortunately something went wrong there, please try again!.</div>");
            }
        }
    }

 

For some reason when the code above is run it executes

 

            if($Class['MySQL']->Query("INSERT INTO xhost_accounts (account_username, account_password, account_email, account_realname, account_regdate, account_regtime, account_level, account_balance, account_notifications) VALUES('".$Class['MySQL']->parseClientInput($AccountUsername)."', '".md5($Class['MySQL']->parseClientInput($AccountPassword))."', '".$Class['MySQL']->parseClientInput($AccountEmail)."', '".$Class['MySQL']->parseClientInput($AccountRealname)."', '".date("d/m/y")."', '".time()."', '0', '0.00', 'Enabled')"))

 

Before it runs:

 

      if($this->isAccountRegistered($AccountUsername, $AccountEmail) == USERNAME_REGISTERED)
        {
            echo("<div class=\"warning\">Unfortunately this username is in use by another member!, please select another!.</div>");
        }

 

Causing it to say that the username is registered every time yet still inserting the account into the database, its returning that its registered because it inserts it before doing the check, does anybody have any idea why, this really has confused me, thanks for your time.

Link to comment
Share on other sites

It might be a problem with the quotes, though I didn't look too deeply, try putting quotes around every instance of EMAIL_REGISTERED and USERNAME_REGISTERED.  Right now it appears you are returning constants instead of strings.

 

If that isn't the problem, you have to realize that what the script is doing is telling you exactly where the problem is.  It is telling you that:

 

$this->isAccountRegistered($AccountUsername, $AccountEmail) == USERNAME_REGISTERED

 

and:

$this->isAccountRegistered($AccountUsername, $AccountEmail) == EMAIL_REGISTERED

 

are both false so it is running the else portion every time.  To test this theory, put this as your else:

 

else {echo 'This is where the problem is'; die(); }

 

If you see that text when you run it, it means what i said above is true.  This tells us the problem with your code is either in the syntax of your if and elseif or, more likely, your code in the isAccountRegistered function is bad in some way.

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.