samedi 3 janvier 2015

POST Array to Multiple Variables

So on one page I have a little form like this



<form method='post' action='trade_confirm.phtml'>
<input type='checkbox' name='items[]' value='" . $row1["inventory_slot"] . "' />
</form>


The form essentially lists multiple checkboxes from a MySQL query, like so:



Item #1 (Checkbox)
Item #2 (Checkbox)
Item #3 (Checkbox)


This is posted to the next page through the _POST["items"] array. I have this on page 2.



if (!empty($_POST['items'])) {
foreach ($_POST['items'] as $selected) {
echo $selected."</br>";
}
}


The echo command returns the output I want.



Item#1
Item#2
Item#3


But how can I assign each of these to a variable such as



$variable1 = Item#1;
$variable1 = Item#2;
$variable1 = Item#3;


(Item#1-3 don't mean anything in the above context. I just don't know what code would go there...)


EDIT


Another alternative: what is the appropriate way to reference EACH individual item in this post array? Where



echo "_POST['items']"


This should 9234 for example.


The "Items" are integers, not strings.





Aucun commentaire:

Enregistrer un commentaire