Get last ID

When a table has an auto-increment column, MySQL generates that value for you when a new row is inserted. Sometimes that is all you need. Other times, right after inserting the row, you also want to know which ID MySQL just assigned to it.

That is what this lesson is about. After a successful insert, MySQLi lets you read the last generated ID from the connection object through insert_id. So the sequence becomes: insert the row, confirm it worked, then read the ID that was just created for that insert.

The important detail is that this only makes sense after a successful insert into a table that actually has an auto-increment column. In your case, practice_users.id fits that perfectly.

This is very useful in real applications. You insert something, get its new ID, and then use that ID right away for the next step, like linking related data or showing a confirmation that points to the newly created record.