473,513 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding to array in session

2 New Member
Hi
I'm quite a newbie and have been struggling with sessions (!)

What I'm trying to do is to add submitted values from a textfield (or ID number) to an array which is in a $_SESSION. ( It's for a book site where customers can click on buttons next to books that come up on a search, each book id is submitted into a session and then they can go to a form page which will have all the books they are interested in filled out automatically in a text area field - or at least that's the idea)

Anyway I can't get the session to "remember" the data submitted to the array between pages. At present there's just a simple test form with a textbox & submit button going to a processing page with the following code :
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. session_start();
  5.  
  6. $AddStuff = $_POST['TestText']; 
  7.  
  8.  
  9. if(isset($_SESSION['stuff']))
  10.  
  11.   $stuff[] = $AddStuff;
  12.  
  13. else
  14.  
  15.   $stuff = array();
  16.  
  17.   $_SESSION['stuff']=$stuff;
  18.  
  19. $stuffNumber = sizeof($stuff);
  20.  
  21.  
  22. ?>
  23.  
The array $stuff() never gets more than 1 and I think it should surely retain the data by adding elements on each submission ? What am i doing wrong and can someone help me out please ?

PS ( Apart from not increasing the size of he array the above works alright )

thanks in advance

Andy
Oct 27 '07 #1
2 2844
pbmods
5,821 Recognized Expert Expert
Heya, Andy. Welcome to TSDN!

The easiest way to do this is to:
Expand|Select|Wrap|Line Numbers
  1. $__form =& $_SESSION['_FORM'];
  2. foreach( $_POST as $_key => $_val )
  3. {
  4.     $__form[$_key] = $_val;
  5. }
  6.  
Note that we are copying to $_SESSION['_FORM'] instead of $_SESSION. This is to prevent a User from hacking the form and setting arbitrary session values.
Oct 27 '07 #2
AndyW2387
2 New Member
Hi

Thank you for your reply. The problem is that I need to add items to an array. Let's say a user selects one book by clicking on the relevant button, they then select another book by clicking on its button and a third book by clicking on its button as well - you have 3 books or whatever the number selected is - there is a "CONTINUE" button to take you to the form which then fills out the "Books selected" text area automatically.

I need the ids or details of all 3 books to appear in the text area box. If it was just a question of one book at a time - I wouldn't bother wih sessions - I would just post - or rather send a GET request to a processing page and fill in the relevant stuff using that.
But that means the customer can only choose one book at a time which is a nuisance - and i thought i could use sessions and arrays to get around it.

Do you see my problem ?

Andy
Oct 27 '07 #3

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

Similar topics

9
3648
by: bajopalabra | last post by:
hi session("myVar") = rs.getRows( ) don't work when number of records is greater than 10 does anybody know WHY ??? is it a Session object limitation ??? thanks
2
5497
by: a | last post by:
I get the error that "Argument"1": cannot convert from 'string' to 'System.Data.DataRow' at the foreach loop to add rows to the DataTable...any ideas how to fix this? Paul ...
4
147011
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
5
2003
by: frothpoker | last post by:
Guys, I have a couple of issues which I am hoping you can provide guidance on... First one:- Is there any way to retain the $_POST values when a user navigates between pages without using...
1
1113
by: Bob | last post by:
Is there a faster way to add an array to a list then looping through the elements like: double toadd; list<doublelistwant; for (int i=0;i<toadd.Length;i++){ listwant.Add(toadd); }
4
1777
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I will have a fixed number of columns in a tablecell array, but the number rows will be dynamic. Is there a way to add array items at run time? -- (i''ll be asking a lot of these, but I find C#...
1
1399
by: JyotiR | last post by:
Hi. Pls help me i have the following code which is having error.This program is being written by Visual studio 2005 Pls help me ASAP. #include "stdafx.h" void fun(int); int arr =...
0
832
by: priyabgajare | last post by:
hi, i want to add array of combo boxes with name cboFee(0),cboFee(1)....like vb. please tell me the solution for that.... thanks in advance... bye.
6
2234
by: chirayu143 | last post by:
adding array into array of strings in c.....
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7177
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
7394
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
7559
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
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.