[COLOR=”navy”]Hi,
I’m hoping someone can lead me in the right direction here. I’m creating a simple shopping cart that I will later pass on to Paypal for payment but my problem is, it won’t add the items to my shopping cart when I click add to cart.
My products are on different pages and I’m not sure if that is going to matter.
When I click “add to cart” nothing gets added and it says my cart is empty. I have two tables with the following columns:
1.
products:
productId
productName
productDesc
productPrice
link (for dynamically creating the page links on the main product page)
productscents
scentId
scentName
scentDesc
Here is the add code that is in my first products page (Elite Hand Cream):[/COLOR]
<?php
if(isset($_GET[‘action’]) && $_GET[‘action’] == “add”) {
$id = intval($_GET[‘id’]);
$desc=intval($_GET[‘desc’]);
if (isset($_SESSION[‘cart’][$id])) {
$_SESSION[‘cart’][$id][‘quantity’]++;
}
else {
$sql3 = “SELECT * FROM products WHERE productId=[$id]”;
$sql4= “SELECT * FROM productscents WHERE scentId=[$desc]”;
$query3 = mysql_query($sql3);
$query4 = mysql_query($sql4);
if(mysql_num_rows($query3) != 0) {
$row3 = mysql_fetch_array($query3);
$row4 = mysql_fetch_array($query4);
$_SESSION[‘cart’][$row3[‘productId’]] = array(“quantity” => 1, “price” => $row3[‘productPrice’], “desc” => $row4[‘scentId’]);
}
}
}
?>
[COLOR=”Navy”]Here is code I have for the $_SESSION:
<?php
if(isset($_SESSION[‘cart’])) {
$sql5= “SELECT * FROM products,productscents WHERE productId IN (“;
foreach($
$sql5 .= $id . “,”;
}
$sql5 = substr($sql,0,-1) . “) ORDER BY productId, scentId ASC”;
$query = mysql_query($sql5);
if(!empty($query)) {
while($row = mysql_fetch_assoc($query)) {
?>
<?php echo $row[‘productName’];?><?php $_SESSION[‘cart’][$row[‘productId’]][‘quantity’];?>
<?php
} } else {
echo “You need to add an item to your cart”;}
}
[COLOR=”navy”]Here is the code that I have for the “add to cart” and “view cart”:
<a href=#&action=add&id=<?php echo $prodId;?>&desc=<?php echo $scent_id[$y];?>>Add to Cart</a><br><a href=”cart.php”>View Cart</a>
[COLOR=”navy”]This grabs the correct product Id and scent Id which I want.
I’m not sure where to begin with this. LOL. I’m new to PHP and I used a tutorial to help with the code.
Any help would be greatly appreciated.