【发布时间】:2015-01-13 17:29:00
【问题描述】:
好的,我有一个带有 1 个输入和一个提交按钮的表单。现在我使用 if/else 语句为该输入做出三个可接受的答案。是的,不,或其他任何东西。这个 if/else 正在工作的事情是代码在页面加载后立即退出 else 函数。我希望在用户输入之前什么都没有,然后它会显示三个答案之一。
Welcome to your Adventure! You awake to the sound of rats scurrying around your dank, dark cell. It takes a minute for your eyes to adjust to your surroundings. In the corner of the room you see what looks like a rusty key.
<br/>
Do you want to pick up the key?<br/>
<?php
//These are the project's variables.
$text2 = 'You take the key and the crumby loaf of bread.<br/>';
$text3 = 'You decide to waste away in misery!<br/>';
$text4 = 'I didnt understand your answer. Please try again.<br/>';
$a = 'yes';
$b = 'no';
// If / Else operators.
if(isset($_POST['senddata'])) {
$usertypes = $_POST['name'];
}
if ($usertypes == $a){
echo ($text2);
}
elseif ($usertypes == $b){
echo ($text3);
}
else {
echo ($text4);
}
?>
<form action="phpgametest.php" method="post">
<input type="text" name="name" /><br>
<input type="submit" name="senddata" /><br>
</form>
【问题讨论】:
标签: php if-statement