Processing an unknown number of POST variables to a DB

Discussion in 'ASP General' started by sarah, Jul 5, 2003.

  1. sarah

    sarah Guest

    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
    sarah, Jul 5, 2003
    #1
    1. Advertising

  2. sarah

    Chris Barber Guest

    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.



    "sarah" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
    >
    >
    >
    Chris Barber, Jul 5, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel
    Replies:
    3
    Views:
    434
    Kevin Spencer
    Mar 30, 2006
  2. Replies:
    0
    Views:
    347
  3. ondekoza
    Replies:
    2
    Views:
    954
    Daniel Dittmar
    Jul 18, 2006
  4. Replies:
    4
    Views:
    346
    Walter Roberson
    Jun 3, 2008
  5. Vincent Arnoux
    Replies:
    1
    Views:
    234
    Arnaud Bergeron
    Aug 11, 2006
Loading...

Share This Page