473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Not displaying the items in the cart

This is my AddToCart.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.    session_start();
  3.  
  4.    // get the product id
  5.    $DVDID = isset($_GET['DVDID']) ? $_GET['DVDID'] : "";
  6.    $name = isset($_GET['NameOfTheDVD']) ? $_GET['NameOfTheDVD'] : "";
  7.  
  8.    /* 
  9.     * check if the 'cart' session array was created
  10.     * if it is NOT, create the 'cart' session array
  11.  . */
  12.    if(!isset($_SESSION['cart'])){
  13.      $_SESSION['cart'] = array();
  14.     }
  15.  
  16.    // check if the item is in the array, if it is, do not add
  17.    if(in_array($DVDID, $_SESSION['cart'])){
  18.       // redirect to product list and tell the user it was added to cart
  19.       header('Location: shop.php?action=exists&id' . $DVDID . '&name=' . $name);
  20.     }
  21.  
  22.      // else, add the item to the array
  23.     else{
  24.     array_push($_SESSION['cart'], $DVDID);
  25.  
  26.     // redirect to product list and tell the user it was added to cart
  27.     header('Location: shop.php?action=add&id' . $DVDID . '&name=' . $name);
  28.     }
  29.  
  30. ?>
this is my basket where it is meant to display the cart

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.        $action = isset($_GET['action']) ? $_GET['action'] : "";
  4.  
  5.     if($action=='removed'){
  6.         echo "<div>" . $_GET['NameOfTheDVD'] . " was removed from cart.</div>";
  7.     }
  8.  
  9.     if(isset($_SESSION['cart'])){
  10.         $ids = "";
  11.         foreach($_SESSION['cart'] as $DVDID){
  12.             $ids = $ids . $DVDID . ",";
  13.  
  14.         }
  15.  
  16.         // remove the last comma
  17.         $ids = rtrim($ids, ',');
  18.  
  19.         require "connect.php";
  20.  
  21.         $query = "SELECT DVDID, NameOfTheDVD, Quantity FROM DVD WHERE DVDID IN ({$ids})";
  22.         $stmt = $dbhandle->prepare( $query );
  23.         $stmt->execute();
  24.  
  25.         $num = $stmt->rowCount();
  26.  
  27.         if($num>0){
  28.             echo "<table border='0'>";//start table
  29.  
  30.                 // our table heading
  31.                 echo "<tr>";
  32.                     echo "<th class='textAlignLeft'>Product Name</th>";
  33.                     echo "<th>Quantity</th>";
  34.                     echo "<th>Action</th>";
  35.                 echo "</tr>";
  36.  
  37.                 //also compute for total price
  38.                 $totalQuantity = 0;
  39.  
  40.                 while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
  41.                     extract($row);
  42.  
  43.                     $totalQuantity += $Quantity;
  44.  
  45.                     //creating new table row per record
  46.                     echo "<tr>";
  47.                         echo "<td>{$name}</td>";
  48.                         echo "<td class='textAlignRight'>{$Quantity}</td>";
  49.                         echo "<td class='textAlignCenter'>";
  50.                             echo "<a href='removeFromCart.php?id={$DVDID}&name={$name}' class='customButton'>";
  51.                                 echo "<img src='images/remove-from-cart.png' title='Remove from cart' />";
  52.                             echo "</a>";
  53.                         echo "</td>";
  54.                     echo "</tr>";
  55.                 }
  56.  
  57.                 echo "<tr>";
  58.                     echo "<th class='textAlignCenter'>Total Price</th>";
  59.                     echo "<th class='textAlignRight'>{$totalQuantity}</th>";
  60.                     echo "<th></th>";
  61.                 echo "</tr>";
  62.  
  63.             echo "</table>";
  64.             echo "<br /><div><a href='#' class='customButton'>Checkout</a></div>";
  65.         }else{
  66.             echo "<div>No products found in your cart. :(</div>";
  67.         }
  68.  
  69.     }else{
  70.         echo "<div>No products in cart yet.</div>";
  71.     }
  72.     ?>
Jan 23 '14 #1
1 2164

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: WindAndWaves | last post by:
Hi Folks I am working with a session and a 'cart' (note that I do not really know what I am doing though). I was wondering if there is some easy way (function) to work out how many items I have...
3
by: help | last post by:
please i need help. I am doing a wed site online shopping system for my school project, which requires some asp coding using vb script. I am new to asp and have no knowledge whatsoever on how to...
7
by: isaac2004 | last post by:
hi i have a basic asp page that acts as an online bookstore. on my cart page i am having trouble generating 3 numbers; a subtotal, a shipping total, and a final price. here is my code i would...
4
by: MrL8Knight | last post by:
Hello, I am trying to build a simple php form based shopping cart using a cookie with arrays. I need to use 1 cookie because each order will have over 20 items. With that said, I realize I need to...
7
by: David Lozzi | last post by:
Howdy, I have a shopping cart in my arraylist. Works great for adding items but I'm displaying the shopping cart in a gridview and the user can update the qty of the items. If they set it to 0,...
0
by: Ken Lameki | last post by:
Hi guys, Needed to know how to display items on a listview and the items on the same listview appear in different colors, say e.g items that need immediate attention are flagged in red for...
3
by: SDyke | last post by:
A servlet runs a connection class to get a set of drawing numbers from an AS400 file. I want to display the result set in a pick list on a JSP so the user can get the detail info from a selected item...
1
by: jecha | last post by:
I'm implementing a shopping cart but am having a problem in checking out a person who has added item in his/her shopping busket.The code for the checkout.php script is given below <?...
4
by: paul.boparai | last post by:
Hi, I have elements tagged with a date attribute in my XML files. The attribute takes in text formatted like so: 2007 Jan 04 2006 Mar 22 Four numbers for the year A space
1
by: jackmcg | last post by:
I just installed Office SP3 last night and today a 2 column listbox with a varying rowsource is not displaying column(1). the rowsourcetype is table/query and the rowsource is set by a click_event...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.