Home > DeveloperSection > Forums > Working with sessions and POST
Simons Hood
Simons Hood

Total Post:70

Points:494
Posted on    November-01-2014 12:50 AM

 PHP Session 
Ratings:


 1 Reply(s)
 1178  View(s)
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']; 

        ?>



jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    November-01-2014 12:52 AM

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']; 
    ?>

Don't want to miss updates? Please click the below button!

Follow MindStick