Many programmers learned the hard way that the scheme you are proposing did not work when they went from a single user to a networked environment.

You've not said what database you are using. If MySQL you can let it's autoincrement increase your key automatically, perhaps feed it back as confirmation of completion. Using this you will not get duplicates as the insert is unique per connection. Check the MySQL docs for the last insert id.

Try this - it works and takes a load off your code.

Alternately, if you want to use your own scheme, establish a lookup table with two fields: keyvalue and tablename. Write a function that with the table name as a parameter, locks the table, retrieves the keyvalue, adds one to it, updates and exits. You will have to test for locks, you may end up with gaps in your key numbers.

If possible, let the database do the work for you.

Regards - Miles Thompson

At 06:11 AM 12/5/2003 -0700, Aleks Kalynovych wrote:
Good morning all,

I have a couple forms that generate a unique ID based on taking the highest
number in the ID column adding 1 to its value. The problem is that I don’t
save that number until the form is submitted. If 2 or more persons fill out
the form at the same time they all get the same
ID number.  I hope that there are some suggestions on how to accomplish this
with a better method

TIA for your help


PHP Database Mailing List (
To unsubscribe, visit:

-- PHP Database Mailing List ( To unsubscribe, visit:

Reply via email to