I have to insert my data into 2 different tables, in the first table I have the following query which works perfectly:
$insertProjectUser = 'INSERT INTO #__pmanager_user (user_cms_id, user_email, user_created_ip) VALUES (' . $user->id . ', "' . $user->email . '", "' . $_SERVER['REMOTE_ADDR'] . '")';
$db->setQuery($insertProjectUser );
$db->query();
This table has an auto-incremented column called project_user_id
and I need this value immediately.
How can I correctly get the "last inserted id"? I tried more solutions like:
- mysqli_insert_id($db)
- $selectedID = insertid()
- mysqli_insert_id($db)
All these solutions provide only zero 0 value.
Updated:
My query is:
$db = JFactory::getDbo();
$insertProjectUser = 'INSERT INTO #__pmanager_user (user_cms_id, user_email, user_created_ip) VALUES (' . $user->id . ', "' . $user->email . '", "' . $_SERVER['REMOTE_ADDR'] . '")';
$db->setQuery($insertProjectUser );
$db->query();
$addressID = $db->insertid();
If I do: echo $addressID
, I get nothing (empty string).