php order form, passing multiple variables
I am creating a order table. my problem I am having is with my form field for each row/record with in the table.
<input type="text" size="4" name="buy_item['2']" value="0">
I am defining each identifier by a similar syntax
buy_item[ item number ]
my problem is when the entire form is sent to through the post request how do I know exactly which items were purchased?
It is possible their could be up to 100 different items, so the post variables can always be changing. what i know how to do is hard code each item into the buy script but i feel that it is much to开发者_JAVA百科 in efficient and would really lack the ability to add items or remove them.
$_POST['buy_item[2]'];
would be the equivalent to the example at the top. but what if someone bought
buy_item['99']
instead of buy_item['2']
If anyone can lead me towards the right direction it would be greatly appreciated.
foreach($_POST['buy_item'] as $item_id=>$amount){
if($amount > 0){
echo $item_id." was bought ".$amount." times";
}
}
精彩评论