Another Shopping cart array issue..Different user

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
svgmx5
Forum Newbie
Posts: 3
Joined: Sun Feb 22, 2009 12:51 am

Another Shopping cart array issue..Different user

Post by svgmx5 »

I've looked over the various topics regarding this, but somehow i'm still stuck on it and can't get my head around it.

Anyway here's what i got and want to do.

What i got is an online store that sells t-shirts mainly, i have the items stored on a database, and t he size's are stored on a separate database.

What i want to do is to when the user adds the item to the cart, it is added in the following way:

item1 small x 3-->this number being the quantity of small t-shirts
item1 large x 2--->same item, but different size

Right now what it does is it displays the item and the number of times i'ts been added to the cart regardless of the size that is chosen.

Anyways, here's what i got, i've being modifying this code to try to make it work, but i can't seem to get it to work

Code: Select all

 
if(isset($_POST['add']) && $_POST['add']){
        
        $productID=intval($_GET['productID']);
        $productSize = $_POST['size'];
        
        if(isset($_SESSION['cart'][$productID][$productSize]) && $_SESSION['cart'][$productID][$productSize]){
            
            $_SESSION['cart'][$productID]['quantity']++;
            
        }else{
            
            $sql = "SELECT * FROM products WHERE productID={$productID}";
            $run = mysql_query($sql) or die (mysql_error());
            $num = mysql_num_rows($run);
            if($num!=0){
                while($fetch = mysql_fetch_array($run)){
                    $productID = $fetch['productID'];
                    $productPice = $fetch['productPrice'];
                    
            $_SESSION['cart'][$productID][$productSize]=array(
                    "quantity" => 1,
                    "size" => $productSize,
                    "productPrice" => $productPice);
            }
            
            
        }else{
                
            $message="This product id it's invalid!";
                
        }
            
    }
        
}
 
Post Reply