In my code below, why is it not incrementing the integers by one each time? For example, say I have 1 OF 5 when I submit the form. After submission, it should be 2 OF 5, but instead, it displays 5 OF 5. This occurs even if I change the maximum from 5 to 3; it starts at 1 OF 3 and jumps immediately to 3 OF 3. This is the code to display the .. OF ..
<h1><?php echo $sessionMinus ?> OF <?php echo $_SESSION['initial_count'] ?></h1>
Below is the code which should increment the value by one each time:
if(isset($_POST['sessionNum'])){
//Declare my counter for the first time
$_SESSION['initial_count'] = $_POST['sessionNum'];
$_SESSION['sessionNum'] = $_POST['sessionNum'];
$_SESSION['sessionCount'] = 1;
}
else if ($_SESSION['sessionCount'] < $_SESSION['sessionNum']) {
$_SESSION['sessionCount']++;
}
$sessionMinus = $_SESSION['sessionCount'];
The code looks fine. However it is possible that the page is being requested in the background without your knowing. For instance a broken image path etc could be landing on this file hence incrementing your counter. To make sure thats not the case, add a new session array var which records the
$_SERVER['REQUEST_URI']or log it to a text file or something.