Wednesday, January 12, 2011

Create new users programatically in drupal


//fill out these values for the user you want to add
$new_users[0] = array(
'name' => 'login_name_here',
'pass' => 'password_here',
'mail' => 'email_here',
'access' => '0',
'status' => 0,
);

//fill out this user for the next user you wish to add. To add more than two, cut and paste this block, making sure to add one number to the variable that immediately follows, $new_users. For instance, the next would be $new_users[2] = arra.... you get the picture.
$new_users[1] = array(
'name' => '2nd-login_name_here',
'pass' => '2nd-password_here',
'mail' => '2nd-email_here',
'access' => '0',
'status' => 0,
);


foreach( $new_users as $key => $value ){
$sql = "SELECT uid FROM {users} WHERE name = '%s'";
$result = db_query( $sql, $new_users[$key]['name'] );
$data = db_result( $result );
print_r($data);
if ( !$data ) {
user_save( NULL, $new_users[$key], NULL );

}
}

?>

No comments:

Post a Comment