Update custom user fields programatically

by Umair Yousaf   Last Updated January 08, 2018 11:07 AM

how can I update custom user fields programmatically?

I've tried this but don't know how to get Id because I have to execute this code automatically on page load ..

$existingUser = user_load($uid);
$edit = (array) $existingUser; 
$edit['field_company_name']['und'][0]['value'] = 'Ciklum';
user_save($existingUser, $edit);
Tags : 7 users


Answers 1


It should be something like this:

$existingUser = user_load($uid);
$existingUser -> field_company_name['und'][0]['value'] = "Ciklum";
user_save($existingUser);
Krishna Mohan
Krishna Mohan
August 03, 2016 06:30 AM

Related Questions




Create A Sort Features In Drupal

Updated April 04, 2015 15:03 PM

Generating user accounts programatically

Updated April 22, 2015 07:03 AM

Can admins create new accounts without passwords?

Updated February 21, 2016 01:03 AM