Processing an unknown number of POST variables to a DB

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
 
C

Chris Barber

Dim parrItems
parrItems = Split(POSTMESSAGE, "DELIMETER")

Dim pstrLastItemName
pstrlastItemName = parrItems(UBound(parrItems))

'Now parse the lat item name after the last '_' to find the number - this
will be number of item groups posted.
plngNumberOfGroups = [Number that is after the last '_' in the item name]
Now you can do:

plngItemsInEachGroup = CLng(UBound(parrItems) / plngNumberOfGroups)

For i = 1 to plngNumber of Groups
'This constitutes a record (eg. all the same ending number).
For j = 1 to plngItemsInEachGroup
'This is each item in the group / record.
Next
Next

Of course, this assumes that the number of items in each group / record is
the same.

Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top