S
sarah
Hi.. I'm having a problem trying to figure out the best way to
process a POST and add items to my database, and hope someone can help
me...
Background:
I have a database that I will use to hold Purchases of Items
Each Item purchased is stored in it's own record:
[item_name][item_number][item_price]....etc...
Orders come in via a POST from a Third Party, over which I have no
control.
In the POST... if there's multiple items that have been purchased,
numbers are appended to the POST variables... i.e. item_name1,
item_name2...etc.
My problem:
Since I don't know beforehand how many items will be included in a
POST, how do I write the code to process the POST and split it up
into individual items to insert into the database, without writing a
lot of extraneous code?
Right now, the only way I can think of doing this is going through the
POST and checking for lots of things that may or may not exist by
checking:
is there an item_name 1... if so, add a record for item_name,
item_number.....etc
is there an item_name 2....if so, insert a record for item_name,
item_number...etc....
...............
is there an item_name100.... if so....
I'm aware that I can use a "For Each" to get all the records out of
the POST... but not knowing which variables will or will not exist, I
would still have to check manually for each one... or so it seems...
I know there must be a good way to do this... but have no idea what it
might be... Can someone please help??
Thanks,
Sarah
process a POST and add items to my database, and hope someone can help
me...
Background:
I have a database that I will use to hold Purchases of Items
Each Item purchased is stored in it's own record:
[item_name][item_number][item_price]....etc...
Orders come in via a POST from a Third Party, over which I have no
control.
In the POST... if there's multiple items that have been purchased,
numbers are appended to the POST variables... i.e. item_name1,
item_name2...etc.
My problem:
Since I don't know beforehand how many items will be included in a
POST, how do I write the code to process the POST and split it up
into individual items to insert into the database, without writing a
lot of extraneous code?
Right now, the only way I can think of doing this is going through the
POST and checking for lots of things that may or may not exist by
checking:
is there an item_name 1... if so, add a record for item_name,
item_number.....etc
is there an item_name 2....if so, insert a record for item_name,
item_number...etc....
...............
is there an item_name100.... if so....
I'm aware that I can use a "For Each" to get all the records out of
the POST... but not knowing which variables will or will not exist, I
would still have to check manually for each one... or so it seems...
I know there must be a good way to do this... but have no idea what it
might be... Can someone please help??
Thanks,
Sarah