%PDF- %PDF-
Direktori : /home/medipszd/www/admin/ |
Current File : //home/medipszd/www/admin/cart_add.php |
<?php include 'includes/session.php'; if(isset($_POST['add'])){ $id = $_POST['id']; $product = $_POST['product']; $quantity = $_POST['quantity']; $conn = $pdo->open(); $stmt = $conn->prepare("SELECT *, COUNT(*) AS numrows FROM cart WHERE product_id=:id"); $stmt->execute(['id'=>$product]); $row = $stmt->fetch(); if($row['numrows'] > 0){ $_SESSION['error'] = 'Product exist in cart'; } else{ try{ $stmt = $conn->prepare("INSERT INTO cart (user_id, product_id, quantity) VALUES (:user, :product, :quantity)"); $stmt->execute(['user'=>$id, 'product'=>$product, 'quantity'=>$quantity]); $_SESSION['success'] = 'Product added to cart'; } catch(PDOException $e){ $_SESSION['error'] = $e->getMessage(); } } $pdo->close(); header('location: cart.php?user='.$id); } ?>