How To Cycle Through possible POST
Posted: Thu Aug 30, 2007 2:57 pm
Hey guys.. I have a very simple problem, and I'm sure the method I have devised is far from optimal, so I come to seek your advice on how you would do this...
I have an ecommerce payment gateway passing back certain parameters about a customer's order using an HTTP POST. The most important parameter of all is the 'product_id' parameter. Each product is assigned a product id such as 'shoes'.
So if a customer orders just the 'shoes' item from the store, one of the parameters passed back to my script is $_POST['product_id'] = 'shoes'.
If a customer orders 'shoes' and a 'hat', then a second product id parameter is posted as 'product_id1' which will equal, of course, 'hat'.
If more items are ordered than two, then there is a product id for each product passed back, and posted variable is incremented like so:
product_id
product_id1
product_id2
product_id3
...and so on.
Problem is I have no idea how many items each customer ordered, so I need a loop to keep checking how many "product_id(X)" variables are present and be able to store each product_id in an array so I know what was ordered.
What is the best way to do this? For the life of me I can't seem to feel confident with anything I've setup. It works, but I'm trying to become a better programmer and not just a hacksaw developer.
Thanks for any help!
I have an ecommerce payment gateway passing back certain parameters about a customer's order using an HTTP POST. The most important parameter of all is the 'product_id' parameter. Each product is assigned a product id such as 'shoes'.
So if a customer orders just the 'shoes' item from the store, one of the parameters passed back to my script is $_POST['product_id'] = 'shoes'.
If a customer orders 'shoes' and a 'hat', then a second product id parameter is posted as 'product_id1' which will equal, of course, 'hat'.
If more items are ordered than two, then there is a product id for each product passed back, and posted variable is incremented like so:
product_id
product_id1
product_id2
product_id3
...and so on.
Problem is I have no idea how many items each customer ordered, so I need a loop to keep checking how many "product_id(X)" variables are present and be able to store each product_id in an array so I know what was ordered.
What is the best way to do this? For the life of me I can't seem to feel confident with anything I've setup. It works, but I'm trying to become a better programmer and not just a hacksaw developer.
Thanks for any help!