Drupal: Storing data in the user profile

If you want to store data in the user profile, here’s an example of a quick and dirty way to do it:

global $user;
if ($user) {
  $array = array('fieldname' => 'value_to_save');
  user_save($user, $array);

Then access it with $user->fieldname. For more configurability, check out the Profile module.

5 responses to “Drupal: Storing data in the user profile”

  1. Luís Gomes says:


    First of all congratulations on your blog!
    You make me understand you I could load or save data in the user profile! :)

    By the way… maybe you could help me:
    I’ve recently installed Drupal 6.x and Privatemsg module but I can’t see where to send msgs to users.



  2. Sacha Chua says:

    Follow up – to add data from hook_user, change the $edit array (second parameter).

  3. Narsing says:

    I need to store data in the data column of the user table.
    How can i do this.

  4. John H says:


    Use node_save() as in Sacha’s example. It will automatically store the additional user data in data column.

  5. TechNikh says:

    This works in one way but views module doesn’t show the profile values stored in this manner. I guess this is because the data is stored in serialized manner an not in database profile table

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>