Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 UTC on 18 March 2024, to get $100 off your ticket.
By Hawkcode on
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
According to the
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().
I trie that and still same
I trie that and still same result:
$someUmail contained a valid user id
Thanks
If you look closely
you'll see that function user_load($uid, $reset = FALSE) does NOT accept an array as an argument.
I tried that:$someUserID =
I tried that:
Same thing, came back as Boolean False. The user does exist by the way.
Thanks
Then you've done something
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.
I debugged this and the
I debugged this and the variable does contain a valid user Id. I confirmed this by searching for it in the Drupal interface.
Try changing this:<?php $user
Try changing this:
To this:
I didn't think the name of
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
Try the following: <?php$user
Try the following:
What happens?
It returned the Admin
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
I would say you can't be
I would say you can't be passing a valid user ID to the function.
Well, what often happens is
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.
Understood, good point.
Understood, good point.
What about this....
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?"
_
<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.
The problem is, in Drupal,
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().
That is what I started
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.