Page 1 of 1

Assigning ID to form data BEFORE posting

Posted: Thu Jan 05, 2006 11:14 am
by michlcamp
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

Posted: Thu Jan 05, 2006 11:26 am
by John Cartwright
You'll have to query to db to find the latest row,

ie..

Code: Select all

SELECT MAX(`order_id`) FROM ....
Although from what I can tell, this doesn't really seem like a good table design to me..

Posted: Thu Jan 05, 2006 11:33 am
by michlcamp
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.

Posted: Thu Jan 05, 2006 11:48 am
by Chris Corbyn
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.
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?

Posted: Thu Jan 05, 2006 11:54 am
by michlcamp
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

Posted: Thu Jan 05, 2006 11:55 am
by John Cartwright
I would probably have a seperate table for storing the next available product order, and base my id's off that.