Jump to content

[SOLVED] $_SESSION data unsetting!


scottybwoy

Recommended Posts

I want to use $_SESSION array as I want to hold some other data too, and this isn't working for some reason.  This script is run three times;

 

1st - Without any data sent - the form is just called.

2nd - With 'custId' sent - this data is then returned to the form.

3rd -With 'company' and 'clientId' sent - then back to the rest of the form.

 

What I want is all of that data stored as it comes available.  Seems simple enough, until I try it.  So what I have created is a $_SESSION var for each piece of data to make it simple;

 

$_SESSION['scustId'] = $custId,

$_SESSION['scompany'] = $company,

$_SESSION['sclientId'] = $clientId,

$_SESSION['sclient'] = $client.

 

Then further down I produce a printout of the $_SESSION data:

<?php
foreach($_SESSION as $key => $value){
	echo "<strong>".$key." : </strong>".$value."<br>";
}
?>

This holds all my $_SESSION vars from other pages in my script, but when it comes to this particular function, it works in a peculiar way.

 

1st execution - Prints out all previous $_SESSION data.

2nd execution - Prints out previous and 'scustId' + 'scompany', so far so good.

3rd execution - Prints out previous and 'sclientId' + 'sclient, 'scustId' + 'scompany' are gone!

 

What could be unsetting this data?  Here's the complete code :

<?php
function saleLoad() {
global $data_array;

$data_array = $_POST;

if (isset($data_array['custId']) && empty($data_array['company'])) {
	$_SESSION['scustId'] = $data_array['custId'];
	$_SESSION['scompany'] = $this->selectRecord('company', 'customers', 'custId', $data_array['custId']);
}

if (isset($data_array['clientId']) && empty($data_array['name'])) {
	$_SESSION['sclientId'] = $data_array['clientId'];
	$_SESSION['sclient'] = $this->selectRecord('name', 'client', 'clientId', $data_array['clientId']);
}

foreach($_SESSION as $key => $value){
	echo "<strong>".$key." : </strong>".$value."<br>";
}

if (!empty($_SESSION['scustId']) && !empty($_SESSION['sclientId'])) {
	//$this->salesPrep($_SESSION['s*']);
}

include_once(MK_SALE_PAGE);

}
?>

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/39462-solved-_session-data-unsetting/
Share on other sites

I'm using classes, so it's already started elsewhere.  I tried that but it just gave me a message telling me that its ignoring that command as it's already started.  Also if you read my post it does mention that it is holding the data stored prior to this script execution.

 

Thanks anyway

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.