简体   繁体   中英

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'";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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