I have a form, index.php which checks to see what $body_include should be before any html is output.
It works fine when it first loads. It loads test.php as $body_include first and the the input fields and button display as they should. Then, when I click the button, based on the code in test.php, it SHOULD change $_SESSION['submit'] to test2.php and then when index.php loads again, it should change $body_include to 'test2.php'
What is happening though is that after clicking the button, I have to click it AGAIN in order to send it to the second page. I really do not understand this behavior. If I put $_SESSION['submit'] without a conditional statement, it redirects right away.
When I echo out $body_include in the body of the form, it return 'test2.php' like it should but even though $body_include has been reassigned properly, it's still loading 'test.php'. But it's only doing that if I use the conditional testing in test.php as you'll see below. I am tearing my hair out over this. It's very frustrating.
I suppose the real question to be asked is: Why does the right page load properly when not processed through a conditional check first but not if it's been processed through a conditional statement?
Here's the files:
//index.php
<?php
session_start();
$header_include = './includes/mainstyle.php';
if(isset($_SESSION['submit'])) {
$body_include = $_SESSION['submit'];
}
Else {
$body_include = "test.php";
}
include ($header_include);
?>
</head>
<body class="twoColFixLtHdr">
<FORM NAME = "MAINFORM" ACTION=<?php echo $_SERVER['PHP_SELF']; ?> METHOD=POST runat="vdaemon">
<!-- begin #header -->
<?php include_once("/includes/incl_header2.php");
?>
<!-- end #header -->
<!-- begin #sidebar -->
<div id="sidebar1">
<?php include ("/includes/incl_sidebar.php");
?>
</div>
<!-- end #sidebar -->
<!-- end #sidebar1 -->
<!-- begin #main content -->
<div id="mainContent">
<?php
echo $body_include;
include($body_include);
#$process =1;
?>
</div>
<!-- end #mainContent -->
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
<br class="clearfloat" />
<div id="footer">
<p> </p>
<!-- end #footer --></div>
<!-- end #container --></div>
</FORM>
</body>
</html
and this:
<?php
Echo "Please log in<br>
Username: <input type='text' name='username' value='' /><br />
Password: <input type='password' name='password' value='' /><br /><br />
Log In <INPUT ID='submit' NAME='submit' TYPE=IMAGE BORDER=0 SRC='../images/wiz_edit.png' VALUE='login'><p>";
//this, without any checks on it will redirect the page to test2.php when index.php reloads.
//obviously, I comment this out in order to test the IF statement below.
$_SESSION['submit'] = 'test2.php';
//This must already be set since I clicked the button, so why doesn't it behave the way the above statement does?
//with this code, when the form reloads, I have to click submit an extra time in order to get it to redirect.
If (isset($_POST['submit'])) {
$_SESSION['submit'] = 'test2.php';
}
?>