MySQL Get Last ID | Tutorial

Опубликовано: 22 Март 2026
на канале: YouAccel
73
0

Course Title: Web Development Masterclass
Course Link: http://youaccel.com/admin/cdisplay.ph...

Facebook:   / youaccel  
Twitter:   / youaccel  
Website: http://youaccel.com

Tutorial Content:

In certain cases you may need to get the id of the last record that was inserted or updated.

We can do that using the mysqli_insert_id function.

We can implement this function in our last script, by inserting the following syntax:

The last id is stored in the last_id variable.

We can then output the variable value in our echo statement.

Let's test the script to make sure it works.

Enter some data into the form and click submit.

We can see the $last_id value was outputted.

Also remember to check PhpMyAdmin to make sure your record was successfully created.