Forum Moderators: coopster

Message Too Old, No Replies

Content of a Session Var not showing up?

         

neophyte

8:03 am on Sep 25, 2006 (gmt 0)

10+ Year Member



Hello all -

I've got something I cant work out - probably just syntax troubles:

I've got this condition:

<select name="adults">
<? for ($i = 1; $i <= 10; $i++)
{
echo ('<option value="' . $i . '"');
if (isset($_SESSION['adults']) && $_SESSION['adults'] == $i)
{
echo (' selected');
}
echo ('>'. $i . '</option>');
}?>
</select>

Problem is that the condition never evaluates to true even though $_SESSION['adults'] does have some int value (from 1 to 10) after it's been "set".

I've got a work-around that does work where I dump the session var into a local and then use the local ($adultsSaved) as the condition trigger, but I can't understand why the same thing won't work by just using $_SESSION['adults'] as the trigger.

Can anyone see where I'm going wrong here?

Neophyte

jatar_k

3:02 pm on Sep 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



do you have session_start() at the top of that script?

neophyte

3:17 pm on Sep 25, 2006 (gmt 0)

10+ Year Member



Really, really simple and stupid mistake - whenever I bounced back to that page I had an include file (in the wrong place) which effectivly blanked all my session vars.

Oops. Lesson learned. All is well now.

Neophyte

jatar_k

3:20 pm on Sep 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



don't feel badly, last week I had a redirect at the bottom of the page that wrongly went to itself

I was trying to look at posted vars and session vars

they were working but when I would redirect again at the bottom it would nuke everything

took me a while to figure out since I was looking at the right page but with no data, now THAT was dumb :)