I have this code below where what should happen is that if the $sessionMinus
(which is a number) is not the same as ($_SESSION['initial_count'])
, then the form submits to itself which I want to happen BUT if $sessionMinus
equals the same number as ($_SESSION['initial_count'])
then I want the form to submit to the create_session2.php.
But the problem is that if I click on the submit button, no matter what happens, it keeps taking me to an error page, no matter if the numbers match or not. Why is this happening? (This happens if I use both == and === signs).
Below is code:
<?php
session_start();
if ($sessionMinus == $_SESSION['initial_count']){
$action = ($sessionMinus == $_SESSION['initial_count']) ? "create_session2.php" : $_SERVER['PHP_SELF'];
}
?>
<body>
<form id="QandA" action="<?php echo htmlentities($action); ?>" method="post" onsubmit="return validateForm(this);" >
...
</body>
Solution is Below:
<?php
session_start();
if ($sessionMinus == $_SESSION['initial_count']){
$action = 'create_session2.php';
}else if($sessionMinus != $_SESSION['initial_count']){
$action = $_SERVER['PHP_SELF'];
}
?>
<body>
<form id="QandA" action="<?php echo htmlentities($action); ?>" method="post" onsubmit="return validateForm(this);" >
...
</body>