Page 1 of 1

Generating an invoice number

Posted: Mon Oct 10, 2005 1:05 pm
by Luke
I am creating a database, and to get an invoice number, I insert a blank row, use mysql_insert_id() to get the id number, and then update that row after getting all the information i need. Is there any danger of two people ordering off the site at once and mysql_insert_id selecting the wrong id?

Posted: Mon Oct 10, 2005 1:22 pm
by Nathaniel
I don't know that I would worry about that myself, but if you are, this guy has an interesting workaround.

Posted: Mon Oct 10, 2005 1:40 pm
by Burrito
I've never run into any issues with mysql_insert_id() not providing me with the latest id.

If you're worried about it though, you could always create another field for the IP address or the like and then select the max id off of the table that matches the same ip.

Posted: Mon Oct 10, 2005 1:45 pm
by Luke
So do guys do that how I do it?

Posted: Mon Oct 10, 2005 1:47 pm
by Burrito
as I said I use mysql_insert_id() and have never had an issue. I've used the scenario I described above for mssql queries though and it worked flawlessly as well.

Posted: Mon Oct 10, 2005 4:46 pm
by timvw