473,378 Members | 1,420 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,378 software developers and data experts.

problem in shopping cart.

i developed session based shopping cart. using this code.

Expand|Select|Wrap|Line Numbers
  1.     $_SESSION['cart'][]= array( 'prd_name' => $prd_name, 'unit_price' => $unit_price,
  2.     'qty' => $qty, 'id_prd' => $id_prd);
and i use this code to display values placed in session.

Expand|Select|Wrap|Line Numbers
  1. foreach($_SESSION['cart'] as $key=>$value){
  2. echo $value['prd_name'];
  3. echo $value['qty']; 
  4. }
Now my question is that. How can i update values placed in a session. i other words how can i update my shopping cart
Nov 26 '08 #1
5 1132
Atli
5,058 Expert 4TB
rahia307.

Bold, italic and underlined text is meant to place emphasis on parts of your text, not the entire question. Making the whole thing bold, underlined AND italic only makes it harder to read and as such is not allowed.

Please remember that when posting in the future!

Thank you.
Moderator
Nov 26 '08 #2
Atli
5,058 Expert 4TB
To update a session variable, you simple re-set it's value, just like you did when you first created it.

The $_SESSION super-global works just like an array, and can be created, edited and unset just like any regular array.

You can see an example of this in this article.
Nov 26 '08 #3
[quote=rahia307;3436578]i developed session based shopping cart. using this code.

Expand|Select|Wrap|Line Numbers
  1.     $_SESSION['cart'][]= array( 'prd_name' => $prd_name, 'unit_price' => $unit_price,
  2.     'qty' => $qty, 'id_prd' => $id_prd);
and i use this code to display values placed in session.

Expand|Select|Wrap|Line Numbers
  1. foreach($_SESSION['cart'] as $key=>$value){
  2. echo $value['prd_name'];
  3. echo $value['qty']; 
  4. }
Now my question is that. How can i update values placed in a session. i other words how can i update my shopping cart
Nov 26 '08 #4
Well when you

Expand|Select|Wrap|Line Numbers
  1. $_SESSION['cart'][]= array( 'prd_name' => $prd_name, 'unit_price' => $unit_price,
  2. 'qty' => $qty, 'id_prd' => $id_prd);
  3.  
you add to the $_SESSION['cart'] array another value. And it is stored like this:

Expand|Select|Wrap|Line Numbers
  1. $_SESSION['cart'][0] = your first product added
  2. $_SESSION['cart'][1] = your second product added
  3. // and so on
  4.  
so you might want to update your session like this ( knowing you $_SESSION['cart'] index. ) :

Expand|Select|Wrap|Line Numbers
  1. $_SESSION['cart'][0]['prd_name'] = 'another value';
Nov 26 '08 #5
Markus
6,050 Expert 4TB
Do not double post your questions.

Moderator.
Nov 26 '08 #6

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

Similar topics

1
by: madison | last post by:
Hi, I am trying to start a website using paypals shopping cart function. If i have 10 items and they sell out, how do I make it so the item is then listed as sold out. The next person would not...
0
by: Tulasi | last post by:
Hello, any one help me the problem due to Shopping cart. I am developping a project in that project,I want to connect shopping Carts in Vb.net.The shopping carts...
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...
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: judge82 | last post by:
Please I need help with this so bad. I have been struggling with it for 2weeks now. on line 206, I what to create a link that will direct you to the detail of the chosen items, like in the...
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.