Created
May 25, 2017 11:19
-
-
Save rintoug/9af225504826fbf1804436532e9faeb6 to your computer and use it in GitHub Desktop.
Simple PHP Shopping Cart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Add to cart | |
if($action=='addcart' && $_SERVER['REQUEST_METHOD']=='POST') { | |
//Finding the product by code | |
$query = "SELECT * FROM products WHERE sku=:sku"; | |
$stmt = $conn->prepare($query); | |
$stmt->bindParam('sku', $_POST['sku']); | |
$stmt->execute(); | |
$product = $stmt->fetch(); | |
$currentQty = $_SESSION['products'][$_POST['sku']]['qty']+1; //Incrementing the product qty in cart | |
$_SESSION['products'][$_POST['sku']] =array('qty'=>$currentQty,'name'=>$product['name'],'image'=>$product['image'],'price'=>$product['price']); | |
$product=''; | |
header("Location:shopping-cart.php"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment