because people may have different products in their shopping cart, so i made an array to display the items. but when I POST those items to checkout_process.php, it only posts the latest item's information.
can anyone help? thanks, here is a part of my code:
Code: Select all
function checkout() {
$output[] = '<form action="checkout_process.php" method="post" id="cart">';
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<table>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM product WHERE product_id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr><td><input type="hidden" name="model" value="'.$model.'"/></td>';
$output[] = '<td><input type="hidden" name="quantity'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
$output[] = '<td><input type="hidden" name="price" value="'.$price.'"/></td>';
$output[] = '<td><input type="hidden" name="price" value="'.($price * $qty).'"/></td>';
$total += $price * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<div><button type="submit">check out</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>You shopping cart is empty.</p>';
}
return join('',$output);
}