Jump to content

Vanishing session


mort

Recommended Posts

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?
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

i thought session_register() was deprecated

This 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 session

any ideas? can post more code if needed but thats all that is really needed from those 2 pages
Link to comment
Share on other sites

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).
Link to comment
Share on other sites

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\" /]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.