View Single Post
  #1 (permalink)  
Old Oct 23rd, 2007, 18:18
andyW8479 andyW8479 is offline
New Member
Join Date: Oct 2007
Location: United Kingdom
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Save data in Arrays during sessions

Hi I'm a new member and I need some help here

I've got a book selling site and I'm trying to create a way of customers clicking on buttons generated from a query and that list of book IDs or titles appearing in a text area box in a form ready for posting as email.

The question is about sessions and arrays

Now I need to preserve data across multiple clicks, as the book IDs are added to an array - registered in a session. My problem - and I think a lot of people have had this - is that the array data is not preserved between pages.

The code i've got so far is :

PHP: Select all

 session_start();
    
    
$AddStuff $_POST['BookText']; 
    
    
     if (!
session_is_registered('stuff'))
    
         {        

        
session_register('stuff');
        
        
$stuff = array();
        
             
         }
         
     if (
session_is_registered('stuff')){

       
        
$stuff[] = $AddStuff;
       
       } 

OK i've used session_register which many say is no good but there is no security issue here - no logins or credit card numbers - just passing info to an email form. And it works - BUT

when I go back and click on another book button the array doesn't get any bigger - there is always just ONE element in it - because the info in the array isn't being preserved 'between' pages.

I understand this is a bug in versions of php after 4.0 or something and I've seen some people recommend $_SESSION - which I've sort of tried but that doesn't even seem to enter one element.

Can anyone help me out here ?

Andy

Last edited by c010depunkk; Oct 23rd, 2007 at 18:21. Reason: added [PHP] tags
Reply With Quote