I have a form that lets the user select an item and input its quantity. My question is how do i echo it in the next page using session? For example if a user selects OPTION-1 with a quantity of 4, the next page would echo Selected:Option1 (4). Any kind of help would be greatly appreciated.
Here's my code:
<label>
<input type="checkbox" name="combos[]" class="drink" value="Title1" data-price="560" />
<input min="0" max="20" type="number" class="quantity" name="comboscount[]" value="true" placeholder="0"/><p>Quantity</p>
</label>
<label>
<input type="checkbox" name="combos[]" class="drink" value="Title2" data-price="322" />
<input min="0" max="20" type="number" class="quantity" name="comboscount[]" value="true" placeholder="0"/><p>Quantity</p>
</label>
<label>
<input type="checkbox" name="combos[]" class="drink" value="Title3" data-price="231" />
<input min="0" max="20" type="number" class="quantity" name="comboscount[]" value="true" placeholder="0"/><p>Quantity</p>
</label>
And here's how I process it in page 2:
$_SESSION['combos'] = $_POST['combos'];
$_SESSION['comboscount'] = $_POST['comboscount'];
if(empty($_SESSION['combos']))
{
echo "Combos: <br />"."Nothing was selected."."<br /><br />";
}
else
{
echo ("Combos: <br />");
foreach ($_SESSION['combos'] as $key => $val) {
echo $val." (".$_SESSION['comboscount'][$key].")<br />";
}
echo ("<br />");
}
I got the array of title to list, but as for the quantity is empty. Did I miss something in the processing of the array?
Once again thanks.
Aucun commentaire:
Enregistrer un commentaire