Returning auto-generated primary key after SQL insertion
0
votes
1
answer
320
views
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
'; }; $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.
'; }; $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.
Asked by CR_BU
(17 rep)
Apr 5, 2015, 02:54 AM
Last activity: May 13, 2025, 07:03 PM
Last activity: May 13, 2025, 07:03 PM