GET request and SESSION variables not working together

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ballinonabudget
Forum Newbie
Posts: 8
Joined: Wed May 27, 2009 6:32 pm

GET request and SESSION variables not working together

Post by ballinonabudget »

I have a form page populated with javascript jump menus. I am trying to pass variables via a GET request into a SESSION variable to the same page so that I can keep my variables every time the page refreshes. Here is one jumpmenu field example:

Code: Select all

 
<select name="series1" onChange="MM_jumpMenu('parent',this,0)">
<?php
while($series = mysql_fetch_array($series_result4)) {
<OPTION value="rf-cable-assemblies-test.php?series1=<?php echo $series['series_abbreviation'];?>" ><?php echo $series['series_name'];?></OPTION>
<?php
}
?>
</select>
 
This is where I pass the GET requests to SESSION variables(scripted on the same page):

Code: Select all

 
$_SESSION['series1'] = $_GET['series1'];
$_SESSION['series2'] = $_GET['series2'];
 
Sessions seem to be working fine. The problem is I would like to store all of these SESSION variables(10 variables total) so that I can use them on the page.. However each time I select a new jump menu, the page refreshes and the SESSION variables get emptied except for whichever GET request I'm sending back to my page.

Is there a better way to get these SESSION variables from these fields without using a GET request? :banghead:

Here is an older example of this form, using all GET requests and no sessions(I am working on a more simplified version on this new version on my local PC)..http://www.rfconnector.com/rf-cable-assemblies.php
Last edited by Benjamin on Fri May 29, 2009 10:23 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: GET request and SESSION variables not working together

Post by Darhazer »

Code: Select all

 
if (isset($_GET['series1']))
    $_SESSION['series1'] = $_GET['series1'];
if (isset($_GET['series2']))
$_SESSION['series2'] = $_GET['series2'];
 
In this way you won't override values if those are not passed in the URL
ballinonabudget
Forum Newbie
Posts: 8
Joined: Wed May 27, 2009 6:32 pm

Re: GET request and SESSION variables not working together

Post by ballinonabudget »

Great thanks!
Post Reply