PHP Adding +1 to a field

Blasteh

big tits
Apr 3, 2013
1,156
521
Hi,
I'm trying to get a referral system working, but for some reason, it wont add +1 to the users referral count.

PHP:
if($template->form->reg_referrer != null)
{
    if(!$this->nameTaken($template->form->reg_referrer))
    {
        $template->form->error = 'The referrer does not exist.';
        return;
    }
    else
    {
        $getReferrerIP = mysqli_fetch_array(dbquery("SELECT ip_last FROM users WHERE username = '". $template->form->reg_referrer ."'"));
        
        if($getReferrerIP['ip_last'] == $_SERVER['REMOTE_ADDR'])
        {
            $template->form->error = 'You cannot refer someone on the same IP.';
        }
        else
        {
            $engine->query("UPDATE users SET refs = refs + 1 WHERE username = '". $template->form->reg_referrer . "' LIMIT 1");
        }
    }
}

I'm not sure where it's going wrong, but everytime a user registers and types in the referrer, it's supposed to +1 to the refs field in `users`.
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
Try This:
Code:
$engine->query("UPDATE `users` SET `refs` = `refs` + 1 WHERE `username` = '". $template->form->reg_referrer . "' LIMIT 1");

Things to verify:
Column name is spelled "refs"
Default value for "refs" is 0 - If it is null , or empty, it will NOT add 1, it will just return null / empty. It should be an int size 11 field with the default of 0.
Remove the Limit on the update query.
Limiting an update query shouldn't affect how the update executes -- Username is an unique field, so it should still be updating his account.


EDIT: If I was coding this, I would code it like this:
Code:
function verifyReferrer($ref){
       $ref = filter($ref);
       if($this->nameTaken($ref)){
           $result = $mysqli->query("SELECT null FROM users WHERE `ip_last` = '". $_SERVER['REMOTE_ADDR']."'");
           if(mysqli_num_rows($result) == 0){
                 return true;
           }else{
              $template->form->error = 'You may not refer this person.';
              return false;
           }
       }else{
        $template->form->error = 'The referrer does not exist.';
        return false;
      }
}
Inside Register Function:
Code:
if(verifyReferrer($template->form->reg_referrer)){
   $engine->query("UPDATE `users` SET `refs` = `refs` + 1 WHERE `username` = '". $template->form->reg_referrer . "' LIMIT 1");
}else{
   return;
}
 
Last edited:

Blasteh

big tits
Apr 3, 2013
1,156
521
Try This:
Code:
$engine->query("UPDATE `users` SET `refs` = `refs` + 1 WHERE `username` = '". $template->form->reg_referrer . "' LIMIT 1");

Things to verify:
Column name is spelled "refs"
Default value for "refs" is 0 - If it is null , or empty, it will NOT add 1, it will just return null / empty. It should be an int size 11 field with the default of 0.

Limiting an update query shouldn't affect how the update executes -- Username is an unique field, so it should still be updating his account.


EDIT: If I was coding this, I would code it like this:
Code:
function verifyReferrer($ref){
       $ref = filter($ref);
       if($this->nameTaken($ref)){
           $result = $mysqli->query("SELECT null FROM users WHERE `ip_last` = '". $_SERVER['REMOTE_ADDR']."'");
           if(mysqli_num_rows($result) == 0){
                 return true;
           }else{
              $template->form->error = 'You may not refer this person.';
              return false;
           }
       }else{
        $template->form->error = 'The referrer does not exist.';
        return false;
      }
}
Inside Register Function:
Code:
if(verifyReferrer($template->form->reg_referrer)){
   $engine->query("UPDATE `users` SET `refs` = `refs` + 1 WHERE `username` = '". $template->form->reg_referrer . "' LIMIT 1");
}else{
   return;
}
Causes registration to turn white after submitting causing an error. Unsure why as stuff is defined in it, but I'm just more concerned why it's not adding +1 to the field as I literally see nothing wrong with it.

I forgot to add, I get this error when the query attempts to execute.
PHP:
PHP Fatal error:  Call to a member function query() on null in C:\\xampp\\htdocs\\plus\\themes\\Alpha\\test12.php on line 2
 

JayC

Well-Known Member
Aug 8, 2013
5,505
1,401
Causes registration to turn white after submitting causing an error. Unsure why as stuff is defined in it, but I'm just more concerned why it's not adding +1 to the field as I literally see nothing wrong with it.

I forgot to add, I get this error when the query attempts to execute.
PHP:
PHP Fatal error:  Call to a member function query() on null in C:\\xampp\\htdocs\\plus\\themes\\Alpha\\test12.php on line 2
Use your code, and change the query to the one I posted check if that works. I'll help you privately on cleaning up the code when I get home
Causes registration to turn white after submitting causing an error. Unsure why as stuff is defined in it, but I'm just more concerned why it's not adding +1 to the field as I literally see nothing wrong with it.

I forgot to add, I get this error when the query attempts to execute.
PHP:
PHP Fatal error:  Call to a member function query() on null in C:\\xampp\\htdocs\\plus\\themes\\Alpha\\test12.php on line 2
 

Blasteh

big tits
Apr 3, 2013
1,156
521
Hi does someone know what swf this is or how to edit it to have it look like this? Also this habbo has their action bar fo stuff like change looks or dance on the left side in where you click me. Pls help...
 
You must be registered for see images attach
Make your own thread, don’t shit post on others.
 
Use your code, and change the query to the one I posted check if that works. I'll help you privately on cleaning up the code when I get home
Will do Jay, thanks for the help. I’ll check when I get home if it works.
 

Users who are viewing this thread

Top