david91 Posted March 30, 2010 Share Posted March 30, 2010 Hey, I have a problem that I cannot solve. I am using the PayPal IPN system and PayPal posts the item details to my ipn.php script. The problem is the item details get posted back to me like this: //example there are 2 items and I want to declare them $item_name_1 = $_POST['item_name_1']; $item_amount_1 = $_POST['item_amount_1']; $item_quantity_1 = $_POST['item_quantity_1']; $item_name_2 = $_POST['item_name_2']; $item_amount_2 = $_POST['item_amount_2']; $item_quantity_2 = $_POST['item_quantity_2']; I want to be able to declare the variables like in the below example, a sort of automatic way: $i = 0; while($row = mysql_fetch_array($sql_get)){ $name = $item_name[$i]; $amount= $item_amount[$i]; $quantity = $item_quantity[$i]; $i++; //some database queries with the defined variables // // } Is there some sort of way to run through all the posted item_name_x, item_amount_x, item_quantity_x because there can be anything from 1 to 100000 item_names, item_amounts and item_quantities posted to the script in that annoying format? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/197044-awkwardly-posted-variables-to-my-script-any-automatic-way-to-run-through-them/ Share on other sites More sharing options...
DavidAM Posted March 30, 2010 Share Posted March 30, 2010 How about something like this: $i = 1; while (isset($_POST['item_name_' . $i])) { $item_name[$i] = $_POST['item_name_' . $i]; $item_amount[$i] = $_POST['item_amount_' . $i]; $item_quantity[$i] = $_POST['item_quantity_' . $i]; $i++; } You may want to add some other checks in there; for example: it assumes (and we all know what that means) that if there is an item_name there is a quantity and an amount to go along with it; you need to sanitize those inputs, just because you expect PayPal to be sending the data doesn't mean that someone else can't be accessing the page with malicious intent; Quote Link to comment https://forums.phpfreaks.com/topic/197044-awkwardly-posted-variables-to-my-script-any-automatic-way-to-run-through-them/#findComment-1034394 Share on other sites More sharing options...
david91 Posted March 30, 2010 Author Share Posted March 30, 2010 Thanks for the quick reply. I'm going to try that now. It looks like it will work. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/197044-awkwardly-posted-variables-to-my-script-any-automatic-way-to-run-through-them/#findComment-1034398 Share on other sites More sharing options...
teamatomic Posted March 31, 2010 Share Posted March 31, 2010 extract($_POST) HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/197044-awkwardly-posted-variables-to-my-script-any-automatic-way-to-run-through-them/#findComment-1034452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.