Is there a way to assign an ID to form data before it's posted to a data table?
I have a form which collects data for product sales but want to automatically assign the order_id value before the form data is posted - in other words, not using an 'auto-incrementing' field in the table as it posts. (I'm using that for something else).
The order_id value would have to be the NEXT number after the previous order.
and, is there a way I can pass that value to the next form using a hidden field?
thanks in advance,
mc
Assigning ID to form data BEFORE posting
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
You'll have to query to db to find the latest row,
ie..
Although from what I can tell, this doesn't really seem like a good table design to me..
ie..
Code: Select all
SELECT MAX(`order_id`) FROM ....- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
You're gonna get into an almighty tangle with that.... if two people access the page at the same sort of time there's a fair chance you'll collide the ID's. Why can't you have another auto-increment column?michlcamp wrote:yeah, I don't think so either...I'm thinking more along the lines of keeping an appendable text file that stores the order_id's - reading it when the form page comes up, assigning the next consecutive number to the order being filled out, then posting that order_id to the table.
agreed again - wanted to create the idea and send the order_id from form to form before posting the order to the database. Trying to avoid having to post then query then post again (or update/insert, whichever the case may be).
The whole thing centers around a second set of forms where additional order info is posted to a different data table.
I'll just go the safe route here I guess
The whole thing centers around a second set of forms where additional order info is posted to a different data table.
I'll just go the safe route here I guess
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: