Another Shopping cart array issue..Different user
Posted: Sun Feb 28, 2010 9:56 pm
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
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!";
}
}
}