Latest member not updating when account created directly in sql

Started by latheesan, October 20, 2014, 06:59:50 PM

Previous topic - Next topic

latheesan

I use the following code to create the forum user account, when someone registers at my site:

// Success
$account_id = DB::insertId();
if ($account_id)
{
// Init Forum DB Connection
$mysqli = new mysqli(
"localhost", // DB Host
"forums", // DB User
"123456", // DB Pass
"forums" // DB Name
);

// Generate SQL
$sql = "INSERT INTO `smf_members` (`id_member`, `member_name`, `date_registered`, `posts`, `id_group`, `lngfile`, `last_login`, `real_name`, `instant_messages`, `unread_messages`, `new_pm`, `buddy_list`, `pm_ignore_list`, `pm_prefs`, `mod_prefs`, `message_labels`, `passwd`, `openid_uri`, `email_address`, `personal_text`, `gender`, `birthdate`, `website_title`, `website_url`, `location`, `icq`, `aim`, `yim`, `msn`, `hide_email`, `show_online`, `time_format`, `signature`, `time_offset`, `avatar`, `pm_email_notify`, `karma_bad`, `karma_good`, `usertitle`, `notify_announcements`, `notify_regularity`, `notify_send_body`, `notify_types`, `member_ip`, `member_ip2`, `secret_question`, `secret_answer`, `id_theme`, `is_activated`, `validation_code`, `id_msg_last_visit`, `additional_groups`, `smiley_set`, `id_post_group`, `total_time_logged_in`, `password_salt`, `ignore_boards`, `warning`, `passwd_flood`, `pm_receive_from`) VALUES
(?, ?, ?, 0, 0, '', ?, ?, 0, 0, 0, '', '', 0, '', '', '', '', ?, '', 0, '0001-01-01', '', '', '', '', '', '', '', 0, 1, '', '', 0, '', 1, 0, 0, '', 1, 1, 0, 2, ?, ?, '', '', 4, 1, '', 1, '', '', 4, 0, '', '', 0, '', 1)";

// Create Forum Account
$now = time();
$ip = GetRealIP();
if ($stmt = $mysqli->prepare($sql)) {
$stmt->bind_param('dsddssss',
$account_id,
$username,
$now,
$now,
$display_name,
$email,
$ip,
$ip);
$stmt->execute();
$stmt->close();
}

// Close Forum DB Connection
$mysqli->close();

// Success
$success = 'Your game & forum account has been created. You may login to Zeal Ragnarok Online server now!';
}


Note* I have purposely left out the password hashing because I implemented my own integrate_verify_user which uses the cookies from login on my site.

My question is, when I create a forum account directly in the DB as shown above, it's not updating the "Latest Member: xxx" on the footer of the fourm. I have to run the "re-count" feature on admin backend for this to update.

Is this because smf has cached the "latest member" or is this because i am not updating some other value in the db to tell smf who is the latest member?

Arantor

That's because you're not supposed to do it directly, like ever.

registerMember() in Subs-Members.php does this and other stuff, and you're supposed to call that.

I would also note that you will need to rewrite this setup if and when you upgrade to SMF 2.1 since the password hash has been changed and all the attendant code has also been changed.

Kindred

Exactly.  Not a bug..  When you byoass the standard protocols to set your own and ignore half of the setup, it is no wonder you encounter errors
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: