markkanning Posted September 26, 2007 Share Posted September 26, 2007 Hello all, I've got a script that, it seems to me should work fine but, alas, it does not. I simply want to change a session variable for a page based on whether or not a form on that page has been submitted. The session variable "page" does nothing more than populate text. Here it is... <?php session_start(); if($submit) { $_SESSION['page'] = "Thank You!"; include "/header.php"; //RESULT OF SUBMITTED FORM HERE include "/footer.php"; } else { $_SESSION['page'] = "Send Us Your Event"; include "/header.php"; //PAGE WITH FORM HERE include "/footer.php"; } ?> The result of this script is I keep getting the form page...no submission and the "page" var stays the same. However, If I break up the session variable declarations and the 2 pages into 2 different IF statements, both requiring the submit var, the form will submit but, once again, the session variable remains the same. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/70796-solved-session-variable-inside-if-statement/ Share on other sites More sharing options...
wildteen88 Posted September 26, 2007 Share Posted September 26, 2007 Where does $submit come from? Is this the name of your submit button? If it is it should be $_POST['submit'] or $_GET['submit'] depending on your forms submit method (this is defined in the form tag). <?php session_start(); include "./header.php"; if(isset($_POST['submit'])) { $_SESSION['page'] = "Thank You!"; //RESULT OF SUBMITTED FORM HERE } else { $_SESSION['page'] = "Send Us Your Event"; //PAGE WITH FORM HERE } include "./footer.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70796-solved-session-variable-inside-if-statement/#findComment-355988 Share on other sites More sharing options...
markkanning Posted September 26, 2007 Author Share Posted September 26, 2007 Sure, I could definitely adjust that part of it. However, is that going to fix the session var issue? Quote Link to comment https://forums.phpfreaks.com/topic/70796-solved-session-variable-inside-if-statement/#findComment-355990 Share on other sites More sharing options...
wildteen88 Posted September 26, 2007 Share Posted September 26, 2007 You'll only know if you test it. I don't know what you doing. I just assumed $submit variable refers to your form's submit button, make sure you have a submit button in your form named submit in order for the if/else statement to work. The problem is to do with the argument in your if statement. Not to do with your session variables. Quote Link to comment https://forums.phpfreaks.com/topic/70796-solved-session-variable-inside-if-statement/#findComment-355995 Share on other sites More sharing options...
markkanning Posted September 26, 2007 Author Share Posted September 26, 2007 Changing to $_POST['submit'] worked. I guess sometimes we just need someone to remind us to keep our code clean. Thanks, Wildteen! Quote Link to comment https://forums.phpfreaks.com/topic/70796-solved-session-variable-inside-if-statement/#findComment-356005 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.