PDA

View Full Version : Populating custom userfields on registration


grey_goose
05-25-2017, 09:19 PM
I run an RPG forum and user accounts are both players -and- characters. I've got a table with character (characters) info and I want to check it to see if a new account is for a character and if it is to populate some custom userfields.

It doesn't work :P

Taking a shot in the dark here, but is it because there's not a username/userid assigned yet? Is there some way to get the information or should I just add a query for the current MAX(userid), increment it, and use that? Or have I made some other mistake?

hook location: register_addmember_complete

// Need to get variables
$getusername = $vbulletin->userinfo['username'];
$getuserid = $vbulletin->userinfo['userid'];

// Need to get Venue info and see if the new account exists as a current character
$result = $vbulletin->db->query_first_slave("
SELECT Venue AS venue
FROM characters
WHERE char_userid = '$getuserid'
");

// If the result is empty it's a player account
// If the result isn't empty proceed
if (!empty($result)) {
$venue = $result['venue'];
$tracker = ''.$getusername.'';

// Update our custom profile fields
$db->query_write("
UPDATE userfield
SET field260 = 'No',
field101 = '$venue',
field209 = '$getusername',
field26 = '$getusername',
field235 = '$tracker'
WHERE userid = '$getuserid'
");
}

MarkFL
05-25-2017, 09:32 PM
Looking at the "register.php" script, it appears that the userid should already be in $vbulletin->userinfo['username'] at that hook location, however, you might try $userid and $username as well. :)

grey_goose
05-26-2017, 12:30 AM
Woof, captain of the S.S. Failboat here.

'char_userid' isn't set yet. Changed to char_name = $getusername worked like a champ.

WHERE char_userid = '$getuserid'