简体   繁体   English

如何将产品尺寸添加到购物车?

[英]How to add product size to cart?

i want to add an select option for the size of product and put it on cart but I don't know where to start, can anyone guide mo on how to add selected product sizes to cart我想为产品尺寸添加一个选择选项并将其放入购物车,但我不知道从哪里开始,谁能指导我如何将所选产品尺寸添加到购物车

<?php
session_start();
error_reporting(0);
include 'connections.php';
if(isset($_GET['action']) && $_GET['action']=="add"){
    $id=intval($_GET['id']);
        
    if(isset($_SESSION['cart'][$id])){
        $_SESSION['cart'][$id]['quantity']++;
        
    }else{
        $sql_p="SELECT * FROM products WHERE id={$id}";
        $query_p=mysqli_query($con,$sql_p);
        if(mysqli_num_rows($query_p)!=0){
            $row_p=mysqli_fetch_array($query_p);
           
            $_SESSION['cart'][$row_p['id']]=array("quantity" => 1, "price" => $row_p['productPrice'],);
    

        }else{
            $message="Product ID is invalid";
        }
     
    }
        echo "<script>alert('Product has been added to the cart')</script>";
        echo "<script type='text/javascript'> document.location ='products.php'; </script>";
}


?>

你的 SQL 应该是

$sql_p="SELECT * FROM products WHERE id LIKE '$id'";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM