Get the last id from a table

If you need an ID before you can get the data from user’s inputs, you can use the query below to get the last id from a table in your database, and then you can increment 1 to that id. For example, a brand new ID can be assigned to an online order using the last id from the table and add 1 to it. Here’s what you can do:
Send a query that return the last id of a table using either query below:

select max(id) from software_order.user limit 1;
select max(id) from software_order.user;

The result is:
3355

Then add 1 to this id, now you’ve got 3356 which will be assign to the new order. This way will ensure that you always have the ID in hand before user enters data into an order form.

If your application just completed an insert statement into software_order.user table, you can use a function called mysql_insert_id() to get the ID generated in the last query. It’s simple to use.
Here’s the example:

$last_id = mysql_insert_id();