mort Posted May 9, 2006 Share Posted May 9, 2006 Howdy all, 1st post :)Having a slight problem with some sessions i am makingI was creating an ordering system with some print options, and you could select a quantity, then proceed to the confirm order page. It sets the sessions dynamically using the product id as the session name ie $_SESSION[$po_id] which i know it sets, as am printing the sessions out at the bottom of the page ie print_r($_SESSION)Anyways, if you press the change order button to go back to the product select screen, the session is no longer set, even though i haven't told it to unset it.Just to make sure i made a file that ONLY displays whats in the sessions, and even that wont see it. Its just strange how its set on one page but not anotherany ideas? Quote Link to comment https://forums.phpfreaks.com/topic/9356-vanishing-session/ Share on other sites More sharing options...
toplay Posted May 9, 2006 Share Posted May 9, 2006 Welcome to these forums!Make sure that you have a session_start() in all the scripts that expect to write or read session values.Take a look at our session troubleshooting guide:[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=31047&view=findpost&p=157705\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=157705[/a]If you're still stuck after viewing that, then please post exact code snippets so members on this forum can help you better. Quote Link to comment https://forums.phpfreaks.com/topic/9356-vanishing-session/#findComment-34493 Share on other sites More sharing options...
mort Posted May 9, 2006 Author Share Posted May 9, 2006 Thanks for the welcome and quick reply :)yes the session is definitley started, as that page is behind a login script i madebasically i put the products in statically at first as there was only a few of them, and it all worked as was supposed to, but when i made it dynamically read the products from a DB it started playing upits definitley setting the session on the page it should, and it wont be unsetting it anywhere as i haven't told it too, so why would it vanish when i move to another page? Quote Link to comment https://forums.phpfreaks.com/topic/9356-vanishing-session/#findComment-34494 Share on other sites More sharing options...
.josh Posted May 9, 2006 Share Posted May 9, 2006 so maybe you aren't pulling the data from the database (properly). have you tried echoing out the results from your query immediately after the query to make sure you got the data you want?also, have you registered your session variables? Quote Link to comment https://forums.phpfreaks.com/topic/9356-vanishing-session/#findComment-34498 Share on other sites More sharing options...
mort Posted May 9, 2006 Author Share Posted May 9, 2006 i thought session_register() was deprecatedThis is from my select print page[code]<?$printoptions = mysql_query("select * from printoptions");while($po=mysql_fetch_array($printoptions)) { $po_id = $po["po_id"]; $po_desc = $po["po_desc"]; $po_size = $po["po_size"]; $po_pdfname = $po["po_pdfname"];?><tr><td width="300"><? echo $po_desc; ?></td><td width="100"><? echo $po_size; ?></td><td width="100"><a href="pdf/<? echo $po_pdfname; ?>" target="_blank">View PDF</a></td><td width="120"><select name="<? echo $po_id; ?>"><option value="0">Select Quantity<option value="500"<? if($_SESSION[$po_id] == "500") { echo " selected"; } ?>>500<option value="1000"<? if($_SESSION[$po_id] == "1000") { echo " selected"; } ?>>1000<option value="1500"<? if($_SESSION[$po_id] == "1500") { echo " selected"; } ?>>1500<option value="2000"<? if($_SESSION[$po_id] == "2000") { echo " selected"; } ?>>2000</select></td></tr><? } ?>[/code]then on the confirm page after that this is some of the session code[code]<?foreach($_POST as $key => $value){ if($value != 0) { $_SESSION[$key] = $value; }}print_r($_SESSION);?>[/code]when i print the session it see's the po_id as the session name, and the quantity as the value, but when i go back to the print select page it should keep the value stored in the select input using the sessionany ideas? can post more code if needed but thats all that is really needed from those 2 pages Quote Link to comment https://forums.phpfreaks.com/topic/9356-vanishing-session/#findComment-34649 Share on other sites More sharing options...
toplay Posted May 10, 2006 Share Posted May 10, 2006 1) I assume $po_id holds numbers. Read item # 25 in the session trouble shooting guide and change code to use names for the session index. You could use a two dimensional array instead i.e. $_SESSION['selections'][$po_id].2) Try code listed in item # 10 and report back what happened. If it's not saving, look at item # 4.3) Read item # 8.4) While testing/debugging this, make sure you have error_reporting(E_ALL); at the top of your script so you can see all of PHP's errors/warnings/notices. Also, I assume you have display_errors on in the php.ini file. Otherwise, set it using ini_set('display_errors', '1'); at the top of your script too.5) Basically, go through the trouble shooting guide and make sure that sessions are being saved from page to page. Then you can work on debugging your code (if it should even need it after that). Quote Link to comment https://forums.phpfreaks.com/topic/9356-vanishing-session/#findComment-34798 Share on other sites More sharing options...
mort Posted May 10, 2006 Author Share Posted May 10, 2006 ahha, the array's key shouldnt have started with a number, i prefixed it with "po_id_" and now it worksthank you very much for the help [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/9356-vanishing-session/#findComment-34866 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.