Forums

php get user id after user registration

Timoa 26 Aug, 2021
Hello

In PHP code I need to get user id after joomla user registration. But I don't know how to do that😟 All my experiments have failed.
I have tried this:
$this->get("joomla_user_82.var.id");
$form->data['joomla_user_82']['var']['id'];

but there was no success to get user id...
    [joomla_user_82] => Array
        (
            [_success] => User saved successfully under id 4543
            [var] => Array
                (
                    [name] => Timo Shḱasie
                    [username] => timoa
                    [email] => test@gmail.com
                    [password] => 
                    [block] => 1
                    [activation] => d1e38289-2327-4211-b97f-fda91306e9a2
                    [registerDate] => 2021-08-26 10:32:51
                    [id] => 4543
                )

        )
Timoa 26 Aug, 2021
OK....one solution that works is this

$db = JFactory::getDBO();
$db->setQuery('SELECT id FROM #__users WHERE username = ' . $this->data("username"));
$user_id = $db->loadResult();
You need to login to be able to post a reply.