GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Dec-2009, 00:36
amber.long83 amber.long83 is offline
New Member
 
Join Date: Nov 2009
Posts: 6
amber.long83 is on a distinguished road

Session array not updating


Hello everyone,

i am trying to build a simple online shopping cart. Been strugling with 2 dimensional sessions array and when i finally got it working the session array is not updating.

I want to be able to browse through each product page and keep adding the productid,quantity to $_session[cart].

But each time i add to cart the previous product ids and quantities are deleted from the session. Am i doing it correctly.

Somebody please help.Thanks in advance.

Code:
PHP Code:

<?php
foreach($_POST as $var => $value)
{
if($value != '')
{
// add to session
$_SESSION['cart'][$var] = $value;
}
}
?>
<?
foreach($_SESSION['cart'] as $pid => $qty)
{
echo "Product id: $pid, Quantity:$qty ";
echo "<br>";
}
?>



Thanks in Advance
Last edited by LuciWiz : 19-Dec-2009 at 04:12. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 19-Dec-2009, 07:35
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,233
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Session array not updating


From page to page, there should be a call to session_start(), or else the information will be lost between page transitions.

Typically, that function is at the top of each page where session use is involved. See this PHP api reference for more info.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 21-Dec-2009, 03:13
amber.long83 amber.long83 is offline
New Member
 
Join Date: Nov 2009
Posts: 6
amber.long83 is on a distinguished road

Re: Session array not updating


Quote:
Originally Posted by TurboPT
From page to page, there should be a call to session_start(), or else the information will be lost between page transitions.

Typically, that function is at the top of each page where session use is involved. See http://us.php.net/manual/en/function.session-start.php for more info.

Thanks for suggetion
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the problem and can you fix it (php) oggie MySQL / PHP Forum 8 14-Apr-2008 15:08
Getting a line error in register oggie MySQL / PHP Forum 5 13-Apr-2008 16:16
What is an array? Howard_L C Programming Language 3 05-Oct-2007 05:11
How to sort in C++ alphabetically wilen C++ Forum 5 20-Apr-2007 14:43
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 19:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:00.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.