Returning auto-generated primary key after SQL insertion I am trying to submit data to a database and then have it return the value of the user_id (primary key) created by the insertion, but I can't get it to return the value. I use the same query in phpAdmin and it works just fine. I know this should be simple, but I just can't get it. Here is my code:

(I do have values to connect to the database, just didn't include them for privacy.)

$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_SITE) 
OR die ('Could not connect to MYSQL: ' . mysqli_connect_error() );
$nameQuery="INSERT into nameReunion 
    (username, password,email,firstName,middleName,lastName, maidenName,     lastUpdate)
VALUES
('$username', '$password', '$email', '$fname', '$miname', '$lname', '$maname', CURDATE());";    

$r = @mysqli_query ($dbc, $nameQuery);


if(!$r) {
echo "The database was not updated.";
} else {
echo 'The connection was successful&lt;br/&gt;';
};

$getUserID="SELECT user_id FROM nameReunion WHERE username='$username';";
$r2=@mysqli_query ($dbc, $getUserID);
echo $r2;
echo $getUserID;


Please help. I have spent wayyy too much time on something I fear should be very simple.
Nevermind. I used mysqli_insert_id and it worked.  The documentation for this solution is available here.