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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀