Bravat Posted June 7, 2011 Share Posted June 7, 2011 I have two sessions on one page: Session #1: if(isset($_POST['sezonaSubmit'])){ $_SESSION['sezona'] = $_POST['sezona']; } else { $_SESSION['sezona'] = "Letnja Guma"; } $sezona = $_SESSION['sezona']; Session #2: if(isset($_POST['poredak'])){ $_SESSION['poredak'] = $_POST['red']; } else { $_SESSION['poredak'] = " ORDER BY price ASC"; } $order = $_SESSION['poredak']; And they are used to change order on the list. Problem is when I change one, other session is changed to the default value. How to fix this? Quote Link to comment Share on other sites More sharing options...
Drummin Posted June 7, 2011 Share Posted June 7, 2011 I think you should wrap each in its own IF statement. IF ($_POST['sezonaSubmit']){ if(isset($_POST['sezonaSubmit'])){ $_SESSION['sezona'] = $_POST['sezona']; } else { $_SESSION['sezona'] = "Letnja Guma"; } }//end if $_POST['sezonaSubmit'] $sezona = $_SESSION['sezona']; IF ($_POST['poredak']){ if(isset($_POST['poredak'])){ $_SESSION['poredak'] = $_POST['red']; } else { $_SESSION['poredak'] = " ORDER BY price ASC"; } }//end if $_POST['poredak'] $order = $_SESSION['poredak']; Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 7, 2011 Share Posted June 7, 2011 You only have ONE session, but you are maintaining two session values. I think the problem is that you have two different forms and based upon which one is submitted you are setting the value for one variable and the other is getting set to the default. You should check to see if the session value was previously set before setting it to the default. For each one I would 1. First check if something was posted (if so use the posted value) 2. Then I would check if the session value was previously set (if not then set to the default) 3. If the session value was already set, then I would do nothing and just use that value if(isset($_POST['sezonaSubmit'])) { $_SESSION['sezona'] = $_POST['sezona']; } elseif(!isset($_SESSION['sezona'])) { $_SESSION['sezona'] = "Letnja Guma"; } } $sezona = $_SESSION['sezona']; if(isset($_POST['poredak'])) { $_SESSION['poredak'] = $_POST['red']; } elseif(!isset($_SESSION['poredak'])) { $_SESSION['poredak'] = " ORDER BY price ASC"; } $order = $_SESSION['poredak']; Quote Link to comment Share on other sites More sharing options...
Bravat Posted June 7, 2011 Author Share Posted June 7, 2011 It is working perfectly . Thank you for help. Quote Link to comment 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.