28 lines
779 B
PHP
28 lines
779 B
PHP
<?php
|
|
session_start();
|
|
|
|
// Check if the product ID is provided
|
|
if (isset($_POST['product_id'])) {
|
|
$productId = $_POST['product_id'];
|
|
|
|
// Initialize the cart if it doesn't exist
|
|
if (!isset($_SESSION['cart'])) {
|
|
$_SESSION['cart'] = [];
|
|
}
|
|
|
|
// Add the product to the cart
|
|
// For simplicity, we just add the product ID.
|
|
// In a real application, you might want to add quantity and other details.
|
|
if (isset($_SESSION['cart'][$productId])) {
|
|
// If product already in cart, increment quantity
|
|
$_SESSION['cart'][$productId]++;
|
|
} else {
|
|
// Otherwise, add product to cart with quantity 1
|
|
$_SESSION['cart'][$productId] = 1;
|
|
}
|
|
}
|
|
|
|
// Redirect back to the products page
|
|
header('Location: products.php');
|
|
exit();
|
|
?>
|