2

I used user_save to update the field. However, whenever I run this function and I log out and try to log back the password doesn't work anymore.I think it cause a change in the password. can anyone help me to get the actual password back?

$existingUser1 = user_load($uid1);
$existingUser1->field_group_id[LANGUAGE_NONE][0]['value'] = $g_id;
user_save((object) array('uid' => $existingUser1->uid), (array) $existingUser1);
4
  • Just for clarification, why do you need your old password? Have you forgotten your new password or you are not aware that with what password it has got saved? Commented Mar 8, 2017 at 6:54
  • I updated one field of all the users using user_save, coz of which password of each-one is changed automatically so to access the system every user will need to-reset the password.Its like we are forcing user to reset the password.
    – Brrocks
    Commented Mar 8, 2017 at 7:14
  • Need to see your code before we can give any kind of effective answer.
    – Jaypan
    Commented Mar 8, 2017 at 8:10
  • @Jaypan i added the code.
    – Brrocks
    Commented Mar 8, 2017 at 9:02

1 Answer 1

2

You probably want this:

$existingUser1 = user_load($uid1);
$existingUser1->field_group_id[LANGUAGE_NONE][0]['value'] = $g_id;
user_save($existingUser1);

You just need to call user_save() on the user object to save the values after you have changed any fields.

6
  • Hey Jaypan, could you please add some explanation for the code you posted. Not doing so is considered as a low quaity post according the Rules (oeps: rules) of this site ... and puts it at risk of beiing deleted via moderation (FYI: your answer did show up in the low quality posts ...). Just a suggestion ... Commented Mar 8, 2017 at 9:25
  • There wasn't much to say, but I added some more.
    – Jaypan
    Commented Mar 8, 2017 at 9:28
  • That's what experts often say ... but your improvement helps for sure. And if you ask me "good enough". So merci for taking my advice ... PS: it also makes your answer "more effective" (as in your own comments to the question ...) Commented Mar 8, 2017 at 9:37
  • @Jaypan the solution provided by you works well.But is there any solution for the problem caused by the previous code?
    – Brrocks
    Commented Mar 8, 2017 at 9:40
  • Pierre - fair enough, I guess after writing code for so long it's easy to forget that it's not always clear to other people what exactly is happening.
    – Jaypan
    Commented Mar 8, 2017 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.