473,396 Members | 2,068 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,396 software developers and data experts.

Session Problem in Shopping Cart

I have problem with this simple shopping cart, I am going to pushing two different value from different table into arrays.
The value is product id & size id, its work to carry the value but the size appear not to be fix inside the cart.

2.php, This page for pushing value inside arrays.
Expand|Select|Wrap|Line Numbers
  1. switch($action){
  2.     case "add":
  3.     $_SESSION['cart'][$prod_id][$size_id]++;
  4.     break;
  5.     case "remove":
  6.     $_SESSION['cart'][$prod_id][$size_id]--;
  7.     break;
  8.     case "empty":
  9.     session_destroy();
  10.     break;
  11. }
  12. header("location:3.php");
  13. ?>
  14.  
3.php, This page for displaying result.
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     foreach($_SESSION['cart'] as $item=>$sizes){
  3.         foreach($sizes as $size){
  4.         $prod = mysql_query("SELECT prod_name,size_id,size_number FROM a_prod,a_size WHERE prod_id='$item' AND size_id='$size'");
  5.             if(mysql_num_rows($prod) > 0){
  6.             list($prod_name, $size_id, $size_number) = mysql_fetch_row($prod);
  7.                 echo "Name : ".$prod_name." - "."Size : ".$size_number." - "."Qty : ".$size.
  8.                 "<a href=\"2.php?prod_id=$prod_id&size_id=$size_id&action=remove\"> - </a><br>";
  9.             }
  10.         }
  11.     }
  12. ?>
  13.  
Question:
1)On the first submission, if I choose size 42, the result display 40 then increment on the next submission and so on.
Since I only have 3 size in my table, when the product submit four times it display nothing.

2)On the second submission and so on(with same product & size), the size_id is increment [1]40 > [2]41 > [3]42:
1.First submission : Fade 40 >> Name : Fade - Size : 40 - Qty : 1 -
2.Second submission: Fade 40 >> Name : Fade - Size : 41 - Qty : 2 -

Someone told me to use var_dump to see the array, but I don't know how to use it to fix my problem.
on : var_dump($_SESSION['cart']);
I got this:
array(1) { [11]=> array(1) { [1]=> int(1) } }
array(1) { [11]=> array(1) { [1]=> int(2) } }

I hope anyone in this forum will help me, because I really need.
Thanks.
May 30 '10 #1
1 1282
dlite922
1,584 Expert 1GB
I don't see your questions, so I don't know what the problem with your code is.

var_dump is used to debug your code, to see what a variable contains so you can see if it's wrong, you'll know where it went wrong instead of waiting till end of the program.


Dan
Jun 4 '10 #2

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

Similar topics

6
by: Fnark! | last post by:
I am creating a shopping cart using PHP Version 4.1.2. I am creating and registering a cart object in a session. The cart object contains an array of arrays called $order whose elements are a...
2
by: Don Grover | last post by:
I am retrieving costs and product id's from a sql db. and need to build a shopping cart around it. How do I store the selected items and qty req so I can move into another catalog and total up as...
9
by: Penny | last post by:
Hi all, I've built an online shopping cart using ASP Classic(based on a 'WebThang' tutorial). The shop cart page (with table showing customers selected items and costs) has only 3 buttons/links....
2
by: Paul Hobbs | last post by:
Hi All, I am developing a site that makes use of a standard shopping cart. Anyone can add items to the cart, but only registered users can actually check out. When a user tries to check out, if...
1
by: Adil Akram | last post by:
I have created a site shopping cart in ASP.net. I am using ASP session object's SessionID on non SSL connection to track session. While adding products to cart DB I insert product and SessionID...
2
by: Guadala Harry | last post by:
I'm looking to implement some *minimal* shopping cart. I've looked at a few 3rd party packages, and they're all way too involved for what I need. So, I'm thinking it might make sense to roll my...
2
by: G.E.M.P | last post by:
High Level Session Handling Design for a Shopping cart 0) What am I missing? 1) How does OSCommerce do it? I'm thinking about building a shopping cart from scratch, using a library of dynamic...
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...
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 <?...
3
by: Paulo | last post by:
Hi, beginner on asp.net 2.0 C# VS 2005, how can I use the shopping cart concept on my application? When the user clicks add item, it will be stored on some storage format, I dont know what is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.