dswwuo1223 2013-05-07 18:51
浏览 18
已采纳

玩会话和POST(会话不会超过2?)

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

Thanks.

  • 写回答

1条回答 默认 最新

  • douzi1991 2013-05-07 18:57
    关注

    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']; 
        ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真