PHP $_SESSION Revision,

I’m doing some PHP revision on the basics of SESSIONS, and i’m struggling to figure out why the code i have below always counts $_SESSION[‘total’] as 0 when i’m trying to add a value to it (laptime – which is the input field),

additionally, is there a better way to incremenent the amount of lap times held in the session variable?

if(!isset($_SESSION['count'])) {
        $_SESSION['count'] = 0;
        $_SESSION['total'] = 0;

    if(isset($_POST['SubmitTime'])) {

        $laptime = $_POST['laptime'];
        if(is_numeric($laptime)) {

            $count = 1 + $_SESSION['count'] ++;
            $total = $_SESSION['total'] + $laptime;

            echo 'You have entered '.$count.' of 5 lap times.';

            if( !isset($_SESSION['min']) || ($laptime < $_SESSION['min']) ) {

                $_SESSION['min'] = $laptime;

            if($_SESSION['count'] == 5) {

                $avg = $total / 5;
                echo '<p style="line-height: 1px;"> Average lap time: '.$avg.'</p>';
                echo '<p style="line-height: 1px;">Fastest lap time: '.$_SESSION['min'].'</p>';
                echo '<p style="line-height: 1px;">Total Time: '.$_SESSION['total'].'</p>';
                echo '<p style="line-height: 1px;">Lap counter reset</p>';

                $_SESSION = array();

        else {echo 'The laptime you have entered is not numeric';}

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s