Forum Moderators: coopster

Message Too Old, No Replies

Too many buttons and too many records

         

Shaman13

9:07 pm on Jan 7, 2005 (gmt 0)

10+ Year Member



I am exhausted trying to figure this one out. Although over the last six months I have banged my head up against the wall a couple of times developing this website I am totally at a loss for how to solve my multiple submit problem. I have scoured the web reading a lot of information about tracking the number of times the button is pushed,automatically moving the user on to the next page and so forth but none seem to fit neatly into a fix for my problem. At this point any and all suggestions are very much appreciated.

I have a data entry form where the user enters information. I use two buttons on this form. The first called Autonumber which uses mysql_insert_id() to pull the number from my MySQL table for the next record to be entered, and another button called Save which allows the user to save the record to the table. My problem is two fold if the user hits Autonumber twice, the first submit pulls a new number from the table and the second submit saves the record. However if the user then hits Save the record is duplicated. This also presents a problem if the user forgets to add a piece of information or wishes to change something after they hit save because it just duplicates the record.

How would I like it to work? If possible I would like to eliminate the AutoNumber button and automatically retrieve the next available number to be assigned when the user opens the form. And, I would like to allow the user to edit the information in the form if they choose to even after they hit Save. I will post relevant portions of the code if that would be helpful, but I really don't want to force someone to read my whole page. Thanks Have a Great Day!

ergophobe

9:51 pm on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure I understand the whole idea behind the Autonumber thing. Is it really necessary to get the row number before the insert? It sounds like a recipe for a lot of empty rows when users open forms, abandon the task, and then open and complete.

Why don't you just insert the user data, then get the row id for the last insertion and show it to the user on a confirmation screen?

An alternative would be to simply create a new row in the DB upon opening a "new record" form and the script would always update and never insert. If you went this route, though, you would need some means of pruning empty rows. One possiblity would be to check whether the last row is empty and, if so, use that one. If not, create a new one. Without understanding the situation though, this all sounds unnecessarily complicated and roundabout.

Also, be aware that though not deprecated, you should keep in mind some of the limitations of mysql_insert_id() [php.net]. In some cases it may be preferable to use the MySQL SQL function LAST_INSERT_ID().