I'm trying to create a checkout page in PHP. The page that lists the items is called shop.php. On this page, I display a number items to be sold with a checkbox beside each item. I'm pulling the item name and price information from the database. Here's my main code.
$row = mysql_fetch_array($query);
while($row) {
echo "<TR>";
echo "<TD><B>$row[Name] </B></TD>";
echo "<TD><B>"."$"."$row[Price] </B></TD>";
echo "<TD><input type=checkbox name=foods[] value='$row[Price]' /></TD>";
echo "</TR>";
$row = mysql_fetch_array($query);
}
<input type="submit" name="buy" value="Buy Now" />
So I am setting the name of the checkboxes to foods[] which'll be an array that'll contain values of all checkboxes submitted. When the user clicks on the "Buy Now" button, they'll be redicted to the cart.php page, that'll display the name and price of the item they've purchased. I know that I can output the prices by looping through the $items array. The problem I have is that I don't understand how would I display the item names. I thoght of doing the following:
$row = mysql_fetch_array($query);
while($row) {
echo "<TR>";
echo "<TD><B>$row[Name] </B></TD>";
echo "<TD><B>"."$"."$row[Price] </B></TD>";
echo "<TD><input type=checkbox name='$row[Name]' value='$row[Price]' /></TD>";
echo "</TR>";
$row = mysql_fetch_array($query);
}
This time, both the name and the price of the items are included in the checkbox as its name and value. But again, the problem is how would I display them on the cart.php page without hard coding. What I means is that how would I display the item name and its price without doing something like this:
(Assume that one of the items name is Burger which was populated as the name of the checkbox.)
if (isset($_POST['Burger'])){
echo "<td>$_POST['Burger']</td>";
}
I'd appreciate any suggestions/tips on this question. Thank you.