Return to Snippet

Revision: 46780
at May 24, 2011 23:48 by Phibo


Initial Code
<?php
$newUser = array(
  'name' => 'username',
  'pass' => 'password', // note: do not md5 the password
  'mail' => 'email address',
  'status' => 1,
  'init' => 'email address'
);           
user_save(null, $newUser);
?>

And, here's how you can update an existing user:

<?php
// load user object
$existingUser = user_load('USERID');

// update some user property
$existingUser->some_property = 'blah';

// save existing user
user_save((object) array('uid' => $existingUser->uid), (array) $existingUser);
?>

Initial URL
http://www.michaelphipps.com/how-create-users-programmatically-drupal-6x

Initial Description


Initial Title
DRUPAL : creation + update user

Initial Tags
drupal, user

Initial Language
PHP