Ian Ian - 3 months ago 9
PHP Question

insert_id not getting the current id

I have been reading the other quotes regarding this and haven't found an answer. I'm trying to return the record id with

insert_id
:

$user = $db->query("
INSERT INTO users(user_name,user_email,user_password,user_salt,
user_vMake,user_vModel,user_dateJoined,user_code)
VALUES ('".$userName."',
'".$userEmail."',
'".$hashedPassword."',
'".$salt."',
'".$userVMake."',
'".$userVModel."',
'".$userDateJoined."',
'".$randomCode."')
");
#Add the user
$newID = $user->insert_id;


If any one has any idea that would be great.

Answer

Solution in your case will be using $newID = $db->insert_id; instead of $newID = $user->insert_id;.