I have a variable known as “$SessionMinus”. What I want to do is that everytime the form is submitted or refreshed, It will add the number by 1 each time so it will start off as 1, then 2, then 3… all the up to the highest number which is “$_SESSION[‘sessionNum’]. How can this be done?
Thanks
<?php
session_start();
$sessionMinus = 1;
if(isset($_POST['sessionNum'])){
//Declare my counter for the first time
if ($sessionMinus < $_SESSION['sessionNum'])
{
$sessionMinus++;
}
$_SESSION['initial_count'] = $_POST['sessionNum'];
$_SESSION['sessionNum'] = $_POST['sessionNum'];
}
?>
<body>
<?php
echo $sessionMinus;
?>
<form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validateForm(this);" >
<p><input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" /></p>
</form>
<?php
$outputDetails = "";
$outputDetails .= "
<table id='sessionDetails' border='1'>
<tr>
<th>Number of Sessions:</th>
<th>{$_SESSION['initial_count']}</th>
</tr>";
$outputDetails .= " </table>";
echo $outputDetails;
?>
</body>
If I understand you correctly, you just have to increment
$sessionMinus++;in your first condition ?This way, everythime someone will submit the form (when
$_POST['sessionNum']is defined),$sessionMinuswill be incremented.