Session Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Emmunis
Forum Newbie
Posts: 1
Joined: Fri Aug 25, 2006 1:18 pm

Session Question

Post by Emmunis »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am posting this message on behalf of one of my developers, so please forgive me if I am not technically precise in my description of the problem.

We’ve been developing a system that utilizes session variables. The system is coded in PHP and our servers are running version 5.0. One of the modules in this system generates data through a five step process (form submissions) and upon approval on the fifth step, writes the results of the other four steps to the database. The data from the steps are stored as session variables and are only written on the final step. The functionality is very similar to a shopping cart.

On step three, a two dimensional array is created and stored as a session variable. The array data is created using data from a table that contains a dynamic number of records. 

At random intervals the session variable fails to create, causing a MySQL error, which excludes this step from the process.

Is there a bug with arrays and sessions that could cause this to occur? Any assistance would be greatly appreciated.

Kind Regards

Code: Select all

<?  

$_SESSION['IMG']=array();

while($fld=$this->GetFields())
	{
	
		$_SESSION['IMG'][] = array('DATE'=>$fld['DATE'],'ID'=>$fld['ID'],'CT'=>$fld['CT'],'STATUS'=>$fld['STATUS'],'LOCATION'=>$fld['LOCATION'],'ORDER'=>$fld['ORDER'],'NOTES'=>$fld['NOTES']) ;
	
	} // - - - while()
	
?>

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What is the MySQL error you are getting? Are you running print_r($_SESSION) at all throughout the processing of the stages, so as to check for errors along the way?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

I'm guessing you are assigning all or nearly all the elements of $fld into $_SESSION['img'][] in your post. If that is the case you could probably save yourself a lot of code:

Code: Select all

// you can unset($fld['unwanted']); too
$_SESSION['IMG'][] = $fld;
That's not going to fix anything though, just thought it might make life a little easier.

Everah's advice is good.
Post Reply