dqm7854 2015-07-10 13:02
浏览 24
已采纳

将值从按钮传递到PHP以输出正确的内容

Below is the code i've been trying to use to make a series of options, some are just 'continue' while others you choose between the options and it changes in which direction the story goes. The code as is is live at thecycle.ie but at the moment when you click 'continue' it changes , correctly to start, and you click it again and it goes back to the first entry.

Basically when you click i want it to store a value, and use that value to check along with $i, which goes up as you go through the game, which choice was made and output the correct values.

$i = 0;
$question = simplexml_load_file('xml/question.xml');
$opt1 = $question->entry[$i]->opt1;
$opt2 = $question->entry[$i]->opt2;

$story = simplexml_load_file('xml/story.xml');
$theSpeaker = $story->entry[$i]->speaker;
$theSpeech = $story->entry[$i]->speech;

echo'<form method="post" action="main.php">';

if($_POST['click']=='opt0' && $i==0)
{
$i = 1;
$theSpeaker = $story->entry[$i]->speaker;
$theSpeech = $story->entry[$i]->speech;
echo '<h2>'.$theSpeaker.'</h2>';
echo '<p>'.$theSpeech.'</p>';
echo '</div>
<div id="menu_about" class="menu_start">
<br>
<button type="submit" name="click" id="submit" value="opt1">'.$opt1.'</button>
</div>
</div>
</div>';
}
elseif($_POST['click']=='opt1' && $i==1)
{
$i = 2;
$theSpeaker = $story->entry[$i]->speaker;
$theSpeech = $story->entry[$i]->speech;
echo '<h2>'.$theSpeaker.'</h2>';
echo '<p>'.$theSpeech.'</p>';
echo '</div>
<div id="menu_about" class="menu_start">
<br>
<button type="submit" name="click" id="submit" value="opt2">'.$opt1.'</button>
</div>
</div>
</div>';
}
else
{
$i = 0;
$theSpeaker = $story->entry[$i]->speaker;
$theSpeech = $story->entry[$i]->speech;
echo '<h2>'.$theSpeaker.'</h2>';
echo '<p>'.$theSpeech.'</p>';
echo '</div>
<div id="menu_about" class="menu_start">
<br>
<button type="submit" name="click" id="submit" value="opt0">'.$opt1.'</button>
</div>
</div>
</div>';
}
  • 写回答

4条回答 默认 最新

  • douyao4632 2015-07-10 13:23
    关注

    In your script delete line 27, there are too many curly braces /THIS ONE/:

    <script type="text/javascript">
    $(document).ready(function() {
    $("body").show();
    $("body").css("display", "none");
    $("body").fadeIn(1000);
    //
    $("#submit").click(function(event) {
    event.preventDefault();
    newLocation = this.href;
    $("body").fadeOut(1000, newpage);
    });
    
    function newpage() {
    window.location = newLocation;
    }  /*THIS ONE*/
    });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点