I'm building e-commerce site, I have checkout page which is the same as cart page,
I want to get all products with their info (quantity selected, price, etc) and put it in 1 query in form to send everything to db.
I am searching for solution for 2 days now , but cant get the $_SESSION array value correctly printed and sent, and how to send multiple products?
the numbers does not update unless i refresh the page too, why?
<form action="#" method="post"> // rest of the form ...
<button class="submit check_out checkout-right-basket">Delivery to this Address</button>
</form>
// I want when submitted to send everything in query to db this form in checkout page
// cart function that display the products in checkout
function cart()
{
$total = 0;
$item_quantity = 0;
$i = 0;
foreach ($_SESSION as $name => $value) {
if ($value > 0) {
if (substr($name, 0, 8) == "product_") {
$length = strlen($name - 8);
$id = substr($name, 8, $length);
$result = query("SELECT * FROM products WHERE product_id = " . escape($id) . " ");
while ($row = fetch_array($result)) {
$i++;
$sub = $row['product_price'] * $value;
$item_quantity += $value;
$product = <<<DELIMETER
<tr class="rem1">
<td class="invert">{$i}</td>
<td class="invert-image">
<a href="single.php">
<img src="{$row['product_image']}" alt=" " class="img-responsive">
</a>
</td>
<td class="invert">
<div class="quantity">
<div class="quantity-select">
<a href="../resources/cart.php?remove={$row['product_id']}"><div class="entry value-minus"> </div></a>
<div class="entry value">
<span>{$value}</span>
</div>
<a href="../resources/cart.php?add={$row['product_id']}"><div class="entry value-plus active"> </div></a>
</div>
</div>
</td>
<td class="invert">{$row['product_title']} </td>
<td class="invert">£{$row['product_price']}</td>
<td class="invert">
<div class="rem">
<a href="../resources/cart.php?delete={$row['product_id']}"><div class="close1"> </div></a>
</div>
</td>
</tr>
DELIMETER;
echo $product;
echo "<pre>";
echo $row['product_title'] . ' - ';
echo $_SESSION['item_quantity'] . ' pices';
echo "</pre>";
// this print wrong quantity for each product , howto print each product with its own quantity?
}
$_SESSION['items_total'] = $total += $sub;
$_SESSION['item_quantity'] = $item_quantity;
}
}
}
}
I expect everything in 1 page and when submitted send query to db and display it in admin area
Hope that was clear, Thanks