0

I created a registration form in PHP, and as soon as the user registers, a message appears stating that the registration was successful, what I want is to be able to put together with this message the ID of this user who has just been registered.

I tried using the code ("SELECT * FROM user ORDER BY id DESC";)

however this code it displays the last one I register and not the one that just registered.

I would like to know how I can display the user ID that has just been registered.

  • https://www.php.net/manual/en/mysqli.insert-id.php will tell you the last ID inserted in your current session (assuming you use an autoincrement field). You can then use that in a select query or pass as a parameter to another script – ADyson Nov 10 '21 at 14:47
  • When someone registers, are they "signed in" or is this just more like a signup form? – Chris Haas Nov 10 '21 at 14:48

1 Answers1

0

the registration process should complete with some result. for example, writing to the session the identifier of the newly registered user. then the identifier can be taken from there. usually, the identifier gets into the session when the following sequence of operations is implemented:

INSERT INTO user ... fields

GET_LAST_INSERT_ID() - the mysqli must have an implementation of this command

and here we have already received an identifier in php

bars
  • 107
  • 5