Search code examples
drupaldrupal-6

Drupal user_save() duplicate email address


I have a module where I try to create some users.

$newUser = array(
        'name' => "Bob",
        'pass' => "pass",
        'mail' => "a@a.com",
        'status' => 1,
        'init' => "a@a.com"
);
$newUserObject = user_save(null, $newUser1);

If a user is all ready created with the same mail address i am not getting false returned I get the user object who all ready existed. Is there any way I can be told that the user all ready exists.


Solution

  • You could try calling user_load with the email address before trying to create the user, to see if it returns a user object. Here's an example (borrowed from here):

    //search by email
    $account = user_load(array('mail' => check_plain($email)));
    if ($account->uid) {
      //user found
    } else {
      //user NOT found
    }