Skip to content
Advertisement

I am trying to get the user id which is created automatically [closed]

$sql4 = "SELECT userid, userName FROM $user_table WHERE userName= '$userNames'";
$result = $conn->query($sql4);
$_SESSION['myUser'] = $result['userid'] ;

I have most code I can find but nothing works

Advertisement

Answer

Assuming these lines of code come immediately after executing an insert of a new user record and you are using PDO. You could try:

$last_id = $conn->lastInsertId();
$_SESSION['myUser'] = $last_id;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement