Updating user fields in Drupal 7 I have created several custom fields for my Drupal 7 users, which I imported from an external users table.

I am now trying to automate the population of these custom fields using a custom module, however my code is not working. The following code is what I have been working with:

&lt;?php

function get_sage_fields($username) {

  // Get the extra fields for Sage users
  $sage_fields = db_query('SELECT OFFICE_ID, TRADE_STATUS, DESIGNATION,
    FIRST_NAME, LAST_NAME, PHONE_NUMBER, MAILING_ADDRESS, ACCOUNT_PREFIX,
    ALLOW_TO_TRADE FROM USER WHERE USER_ID = $username');
  return $sage_fields;
}

function sage_fields_user() {

  // Grab all usernames from the users table
  $usernames = db_query('SELECT name FROM users')-&gt;fetchCol();

  // Load the users
  $users = user_load_multiple($usernames);

  // Loop through and edit each user
  foreach($users as $user) {

    // Load the extra data
    $extra_data = get_sage_fields($user-&gt;name);

    // Update user fields
    $user-&gt;field_office_id[$user-&gt;language][0]['value'] = $extra_data['office_id'];
    $user-&gt;field_trade_status[$user-&gt;language][0]['value'] = $extra_data['trade_status'];
    $user-&gt;field_designation[$user-&gt;language][0]['value'] = $extra_data['designation'];
    $user-&gt;field_first_name[$user-&gt;language][0]['value'] = $extra_data['first_name'];
    $user-&gt;field_last_name[$user-&gt;language][0]['value'] = $extra_data['last_name'];
    $user-&gt;field_phone_number[$user-&gt;language][0]['value'] = $extra_data['phone_number'];
    $user-&gt;field_mailing_address[$user-&gt;language][0]['value'] = $extra_data['mailing_address'];
    $user-&gt;field_allow_to_trade[$user-&gt;language][0]['value'] = $extra_data['allow_to_trade'];

    // Save the user object
    user_save($user);
  }
}


I enabled my custom module under admin/modules and included it in my .info file with:

files[] = sage_fields.module

However, if I go to field_revision_[FIELD_NAME] in my D7 database, I do not see these fields populated.

Could someone please point out where I have gone wrong?
So Simple. just paste it

$user_fields = user_load($user-&gt;uid);    
$user_fields-&gt;field_points['und'][0]['value'] = $points;
user_save($user_fields);