HI,

I have a script that works in our D6 site that reads a CSV file and Updates the User Record Profile Fields and sets their Access level.

I'm calling it like:

  $someUmail = $UserRecord[$NoEmail];
   
  $user = user_load(array('mail' => $someUmail));

$NoEmail Contains the Email address in the $UserRecord Array at Position 2

$someUmail contains the email address,

The user_load always returns boolean false

I even put a valid userid in the $someUmail and user_load still returned false.

Anybody have an idea of whats wrong?

Thanks

Rich

Comments

tce’s picture

According to the documenation, user_load() can only take the user ID as the first parameter and not an array.

If you need to load the user by their email address, I would use user_load_by_mail().

Hawkcode’s picture

I trie that and still same result:

$user = user_load(array('user' => $someUmail));

$someUmail contained a valid user id

Thanks

yelvington’s picture

you'll see that function user_load($uid, $reset = FALSE) does NOT accept an array as an argument.

Hawkcode’s picture

I tried that:


$someUserID = $UserRecord[$NoUserID];
   
 $user = user_load($someUserID);

Same thing, came back as Boolean False. The user does exist by the way.

Thanks

Jaypan’s picture

Then you've done something wrong, because user_load() with a valid user ID will load a $user object. This means that the value you think you are passing as a user ID isn't a user ID.

Hawkcode’s picture

I debugged this and the variable does contain a valid user Id. I confirmed this by searching for it in the Drupal interface.

Jaypan’s picture

Try changing this:

 $user = user_load($someUserID);

To this:

 $account = user_load($someUserID);
Hawkcode’s picture

I didn't think the name of the Variable could have anything to do with it and I was correct.

Same result: $account returned value is boolean False.

Anybody else have an Idea.

Thanks

Rich

tce’s picture

Try the following:

<?php
$user = user_load(1);
?>

What happens?

Hawkcode’s picture

It returned the Admin Account.

Thats calling it by the Account Number. So why can't it find it when I pass a UserID?

This is something though.

What should i do next?

Thanks

Rich

tce’s picture

I would say you can't be passing a valid user ID to the function.

Jaypan’s picture

Well, what often happens is that people declare the $user object global, then do something like $user = user_load() later in the script, which changes the value of the global. I was making sure that you hadn't done that. On that note, it's a best practice to use $account instead of $user when referring to account other than the current user.

Hawkcode’s picture

Understood, good point.

Hawkcode’s picture

Hi,

First as I said earlier I am passing a valid user id, the Id I Passed is "Thomas40140". The user does exist.

But I had another Idea. I will post this in a different Thread call "Any problem accessing the User records from outside Drupal?"

WorldFallz’s picture

<sigh>, that is not a valid user id (I suspect it's a username), which a careful reading of https://api.drupal.org/api/drupal/modules%21user%21user.module/function/... would have pointed out.

Jaypan’s picture

The problem is, in Drupal, that is not a User ID (UID). The User ID is an integer, created as an auto-increment column in the {users} table of the database. Therefore your alphanumeric "Thomas40140" is not a valid User ID, it's an invalid User ID. What it is, is a username, and as such, you want the function user_load_by_name().

Hawkcode’s picture

That is what I started thinking after the last messages.

Thanks for sorting this out everyone. I guess I need to read details a little closer.

Thanks Again.