Gossamer Forum
Home : General : Internet Technologies :

PHP Reserving Incremental Numbers

Quote Reply
PHP Reserving Incremental Numbers
I am writing a script for a multi-user environment where when they click on "Add New Form" the computer will find the next number available and assign it to that form. (Easy enough.) Since it is a multi-user environment, I need to reserve that number so the next person doesn't use the same number. (Still not so bad.) However, if the person filling out the form changes their mind and cancels out of the form or clicks on another link or closes the browser, etc., the numbering sequence is messed up and it has to stay consecutive with no missing numbers.

I have thought about the most efficient way to make this happen and all that has resulted is my head hurts :)

Has anyone done anything similar, and if so, what method did you use?

Thanks.
Quote Reply
Re: [Lee] PHP Reserving Incremental Numbers In reply to
Does the user need to do anything with the number? Do they ever see that data or is it hidden?

Don't assign this data until after these requirements are met:
1) the user submits the form
2) the form passes any required validation checks

Then, and only then, you should:
3) assign the incremental number at the time of insertion into your database

That is really the only way to do it to avoid skipping numbers and prevent users from duplicating the assigned number.

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] PHP Reserving Incremental Numbers In reply to
I'm sorry, I should have stated that yes, the user does need that number at the time they fill out the form. That is what makes this such a pain in the rear.

Thanks for your insight.
Quote Reply
Re: [Lee] PHP Reserving Incremental Numbers In reply to
What's done with it? That might not entirely rule this method out. What does a sample submition look like?

Philip
------------------
Limecat is not pleased.