1

我开始做一个步骤系统,投票给这个页面,然后下一步。

我测试了会话现在是如何工作的,并试图让它每当你点击继续时,它会在会话号上加 1:

$_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;
    }
}

但是现在,当我单击继续时,它会变为 2,这很好,但是当我再次单击继续时,它会停留在 2?

怎么了?

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

谢谢。

4

1 回答 1

1

在任何 html 代码之前开始会话session_start()
你需要这样的东西吗?

    <?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']; 
    ?>
于 2013-05-07T18:57:28.073 回答