scottybwoy Posted February 21, 2007 Share Posted February 21, 2007 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. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 21, 2007 Share Posted February 21, 2007 You need to have session_start(); at the top of the page you are using sessions on. Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted February 21, 2007 Author Share Posted February 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.