ivytony Posted February 17, 2008 Share Posted February 17, 2008 After a customer places an order on my online eshop, I would like to show him/her the order number (the primary auto-incremented ID in mysql database table 'order') on the confirmation page and send the order number to his/her email automatically. My thinking is to get the last auto-incremented ID and then plus 1 as the order number. Is this right to do? I am wondering how to do this? thanks! Link to comment https://forums.phpfreaks.com/topic/91477-how-to-retrieve-the-last-auto-incremented-id/ Share on other sites More sharing options...
tippy_102 Posted February 17, 2008 Share Posted February 17, 2008 I wouldn't do it that way because someone else may place an order that gets written to the database before the first person completed their order. I would write it to the database, then grab the id to display the order number to the user. Link to comment https://forums.phpfreaks.com/topic/91477-how-to-retrieve-the-last-auto-incremented-id/#findComment-468617 Share on other sites More sharing options...
ivytony Posted February 17, 2008 Author Share Posted February 17, 2008 I found php has a function called mysql_insert_id, which can retrieve the latest auto increment id from last insert. Is this good? thanks! Link to comment https://forums.phpfreaks.com/topic/91477-how-to-retrieve-the-last-auto-incremented-id/#findComment-468907 Share on other sites More sharing options...
pocobueno1388 Posted February 17, 2008 Share Posted February 17, 2008 I found php has a function called mysql_insert_id, which can retrieve the latest auto increment id from last insert. Is this good? Yes, that is the correct function to use in this case Link to comment https://forums.phpfreaks.com/topic/91477-how-to-retrieve-the-last-auto-incremented-id/#findComment-468924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.