By rampar on
Ok, I'm using user_save to update the email address field
$array = array('mail' => $emailfield);
user_save($uid, $array);
I keep getting this error. I have no idea why it's trying to create a new account with the $uid, since that's the user I'm specifying I want the email field to change.
user warning: Duplicate entry '' for key 2 query: INSERT INTO users (mail, created, access) VALUES ('test@theemailtest.com', 1240069427, 1240069427) in /Applications/MAMP/htdocs/aurum/modules/user/user.module on line 327.
Any help would be greatly appreciated!
Comments
I think user_save is just broken
user_save's UPDATE just doesn't work, it might be a bug or something, I don't know.
Anyway, if you want to do it, just use your own UPDATE
Same error
I'm getting the same error message, although for me the save function is working. It just seems to be trying to save twice. Unfortunately I can't save directly to the user table, we're in a many-site environment with a shared users table.
BTW - I think you're code is incorrect. Rather than pass in the uid, you need to pass in the user object itself, like so:
For me it's working, but I need someway to kill the error message?
resolved the issue
I was implementing the hook_user in custom module, and I discovered that in the case the $op is set to "edit" - then user_save() is automatically called behind the scenes. So no need to call that function in the edit case. Simply adding the extra custom user fields to the $edit variable of the hook_user method will suffice.
Also, be aware that with user_save(), if it finds a $uid it automatically attempts to run the "edit" case of any implementation of hook_user(). So attempting to run user_save() inside the "insert" case will also run the "edit" case. This happens because the real insert seems to be performed before the case "insert" of a hook_user method, thus a $uid is already created.
My finished code: