Jump to content


Photo

Vanishing session


  • Please log in to reply
6 replies to this topic

#1 mort

mort
  • Members
  • PipPipPip
  • Advanced Member
  • 82 posts

Posted 09 May 2006 - 02:13 AM

Howdy all, 1st post :)

Having a slight problem with some sessions i am making

I 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 another

any ideas?

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 09 May 2006 - 02:28 AM

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.

#3 mort

mort
  • Members
  • PipPipPip
  • Advanced Member
  • 82 posts

Posted 09 May 2006 - 02:32 AM

Thanks for the welcome and quick reply :)

yes the session is definitley started, as that page is behind a login script i made

basically 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 up

its 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?

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 09 May 2006 - 02:43 AM

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?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 mort

mort
  • Members
  • PipPipPip
  • Advanced Member
  • 82 posts

Posted 09 May 2006 - 04:04 PM

i thought session_register() was deprecated

This is from my select print page
<?
$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>

<? } ?>

then on the confirm page after that this is some of the session code

<?
foreach($_POST as $key => $value){
    if($value != 0) {
        $_SESSION[$key] = $value;
    }
}

print_r($_SESSION);

?>

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 session

any ideas? can post more code if needed but thats all that is really needed from those 2 pages

#6 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 10 May 2006 - 02:03 AM

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).


#7 mort

mort
  • Members
  • PipPipPip
  • Advanced Member
  • 82 posts

Posted 10 May 2006 - 10:33 AM

ahha, the array's key shouldnt have started with a number, i prefixed it with "po_id_" and now it works

thank 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\" /]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users