/    Sign up×
Community /Pin to ProfileBookmark

Won’t Add Item to the Cart

[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)

  • 2.

    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:[/COLOR]

    <?php
    if(isset($_SESSION[‘cart’])) {
    $sql5= “SELECT * FROM products,productscents WHERE productId IN (“;
    foreach($_
    SESSION[‘cart’] as $id => $value) {
    $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”:[/COLOR]
    <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.[/COLOR]

    to post a comment
    PHP

    0Be the first to comment 😎

    ×

    Success!

    Help @mrzebra spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.25,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...