Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Session Array Problem
Old 09-07-2007, 06:30 AM Session Array Problem
Novice Talker

Posts: 7
Name: Glen
Trades: 0
Hi,

I am having a problem with a session array in a shopping cart.....

I have a session array for each attribute of the product eg

sofa_name, sofa_id, sofa_type etc

The first product entered into the cart is fine, but when I add a second and subsequent product two of the session arrays do not write properly, they add to the existing value and do not create another element in that array...what is strange only 2 behave like this....

Here is the code that I use to add to the arrays:

$_SESSION['sofa_id'][$newnum]=$new_sofa_id;
$_SESSION['sofa_type'][$newnum]=$new_sofa_type;
$_SESSION['sofa_series_name'][$newnum]=$new_sofa_series_name;
$_SESSION['sofa_series_price'][$newnum]=$new_sofa_series_price;
$_SESSION['sofa_width'][$newnum]=$new_sofa_width;
$_SESSION['sofa_depth'][$newnum]=$new_sofa_depth;
$_SESSION['sofa_height'][$newnum]=$new_sofa_height;
$_SESSION['sofa_name'][$newnum]=$new_sofa_name;
$_SESSION['sofa_type_name'][$newnum]=$new_sofa_type_name;
$_SESSION['sofa_supplement_name'][$newnum]=$new_sofa_supplement_name;
$_SESSION['sofa_supplement_price'][$newnum]=$new_sofa_supplement_selling_price;
$_SESSION['sofa_material'][$newnum]="";

and here is the session variable
sofa_id|s:2:"11";sofa_type|a:2:{i:0;s:1:"1";i:1;s: 1:"2";}sofa_series_name|a:2:{i:0;s:1:"A";i:1;s:1:" A";}
sofa_series_price|a:2:{i:0;s:6:"997.50";i:1;s:6:"5 33.75";}
sofa_width|a:2:{i:0;s:3:"165";i:1;s:3:"187";}sofa_ depth|a:2:{i:0;s:2:"87";i:1;s:2:"87";}

sofa_height|a:2:{i:0;s:2:"65";i:1;s:2:"56";}
sofa_name|s:5:"DDtti";
sofa_type_name|a:2:{i:0;s:7:"Set 3+2";i:1;s:10:"Sofa 3 Plz";}sofa_supplement_name|a:2:{i:0;N;i:1;N;}
sofa_supplement_price|a:2:{i:0;N;i:1;N;}
sofa_material|a:2:{i:0;s:0:"";i:1;s:0:"";}

note that it is the sofa_id array and sofa_name array that are behaving strangely, there is only 1 element in them and there should be 2...ie sofa_id|a:2:{i:0;s:1:"1";i:1;s:1:"1";} and sofa_name|a:2:{i:0;s:5:"Dutti";i:2;s:5:"Dutti";}

php seems to be appending them when it should be creating a new element in the array...does anyone know what is happenning?

Thanks,

Glen
poachedeggs is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-07-2007, 09:35 AM Re: Session Array Problem
Novice Talker

Posts: 7
Name: Glen
Trades: 0
..just in case anyone gets this problem in the future....

I have resolved the problem. How?

I renamed the session variables sofa_id to sofa_model and sofa_name to sofa_model_name...how this fixed it or why the original problem occurred remains a mystery, so if anyone knows, please share...

Glen
poachedeggs is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Session Array Problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.54660 seconds with 12 queries