MyBB Community Forums

Full Version: Database field not updating using PHP in Users.php?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Long story short, my site has some custom code that adds currency to users upon posting (PHP in the /inc/datahandlers/post.php file). That works properly.  Likewise, there's custom code in the /admin/modules/user/users.php file that allows admins to see and edit this currency field in the Admin CP.

Sadly upon upgrade some of this was lost and I'm trying to piece it back together. Everything works perfectly, except this field "Gemstones" being updated via Admin CP.

In the users.php file I have this code:

Quote:// Update user gemstones count
$query = $db->simple_select("users", "gemstones", "uid='".$destination_user['uid']."'");
$num = $db->fetch_array($query);
$updated_count = array(
"gemstones" => $num['gemstones']
);
$db->update_query("users", $updated_count, "uid='{$destination_user['uid']}'");

Is this correct/should this work to update that DB field properly? I see it, but it doesn't actually seem to edit. If yes, is there some other file I'm missing somewhere that needs to be edited?

Sorry if this makes no sense, I'm not the one who wrote this code and am kind of panicking.. thanks for any help!!!
Have you looked into the actual database field if its really getting updated or not?
It may be the cause that the field is being updated but your renderer code is using some cache.
In that case the cache is required to be updated as well after committing the changes to database.
You are selecting user gemstones from the users table and then you are updating the user with the same fetched data. That does not have sense at all. What you should do is to look at similar fields like postnum or threadnum on admin/modules/user/users.php and imitate them for your gemstones system.

I have not tested it, but looking at this file fastly, what you could do is:

Search:
"threadnum" => $mybb->input['threadnum'],

Add under:
"gemstones" => $mybb->input['gemstones'],

Search:
$form_container->output_row($lang->thread_count." <em>*</em>", "", $form->generate_numeric_field('threadnum', $mybb->input['threadnum'], array('id' => 'threadnum', 'min' => 0)), 'threadnum');

Add under:
$form_container->output_row("Gemstones <em>*</em>", "", $form->generate_numeric_field('gemstones', $mybb->input['gemstones'], array('id' => 'gemstones', 'min' => 0)), 'gemstones');

And you should be fine.
p.s. If you handle the whole system via plugin, is better for maintainability. Core edits should be done only when you really can not handle something with a plugin.