WORKING WITH SESSIONS AND POST

Simons Hood

Total Post:70

Points:494
Posted by  Simons Hood
PHP
 1522  View(s)
Ratings:
Rate this:

I am starting to make a step system, vote for this page, and then next step.

I tested how sessions work now, and trying to make it so whenever you click continue, it will add + 1 to session number:

$_SESSION['vote_id'] = 1;

if (isset($_POST['continue']))
{
    if ($_SESSION['vote_id'] == 1)
    {
        $_SESSION['vote_id'] = 2;

    }
    else if ($_SESSION['vote_id'] == 2)
    {
        $_SESSION['vote_id'] = 3;
    }
}

But now, when I click continue, it goes to 2, that's nice, but when I click continue again, it stays at 2?

What's wrong?

<?php

            if (isset($_SESSION['vote_id']))

            {

                if ($_SESSION['vote_id'] == 1)

                {

                    echo '1';

                }

                else if ($_SESSION['vote_id'] == 2)

                {

                    echo '2';

                }

                else if ($_SESSION['vote_id'] == 3)

                {

                    echo '3';

                }                   

            }

        ?>

        <span id="head">Welcome</span><br /><br />

        <span id="paragraph">

        We currently have 7 voting sites. 

        Don't be afraid! We do NOT require you to vote on them all.

        You will receive one point per vote, to finish voting, please click on the

        button "Finish Voting" ad you will receive your points

        </span><br /><br />

        <form action="index.php" method="post">

        <span id="head">Voting site 1: Runelocus</span><br /><br />

        <div class="button" name="runelocus">Runelocus Vote</div><br /><br />

        <input type="submit" class="button_green" id="right" name="continue" value="Continue">

        </form>

        <?php

            echo $_SESSION['vote_id']; 

        ?>

  1. jacob rasel

    Post:88

    Points:616
    Re: Working with sessions and POST

    Start the session before any html code session_start()
    Do you need something like this ?


    <?php
        session_start();
            if (isset($_SESSION['vote_id']))
            {
                $_SESSION['vote_id'] +=1;                 
            }
            else
            {
                $_SESSION['vote_id'] =0;
            }
        ?>
        <span id="head">Welcome</span><br /><br />
        <span id="paragraph">
        We currently have 7 voting sites. 
        Don't be afraid! We do NOT require you to vote on them all.
        You will receive one point per vote, to finish voting, please click on the
        button "Finish Voting" ad you will receive your points
        </span><br /><br />
        <form action="index.php" method="post">
        <span id="head">Voting site 1: Runelocus</span><br /><br />
        <div class="button" name="runelocus">Runelocus Vote</div><br /><br />
        <input type="submit" class="button_green" id="right" name="continue" value="Continue">
        </form>
        <?php
            echo $_SESSION['vote_id']; 
        ?>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!