【发布时间】:2020-07-12 08:31:59
【问题描述】:
我正在开发一个石头剪刀布游戏来练习我的 html 和 php,一切都很好,直到我尝试在 POST 中提交用户选择的答案。我一直在检查,按下button Play 时没有提交任何内容。
这是我的html 代码:
<html>
<head>
<title>Oscar Felipe Ramírez Pardo</title>
<meta charset="UTF-8">
</head>
<body>
<h1>Rock Paper Scissors</h1>
<p>Welcome: <?=htmlentities($_GET['name'])?></p>
<forms method="POST">
<p>
<select name="option">
<option value="Select" checked>Select</option>
<option value="Rock">Rock</option>
<option value="Paper">Paper</option>
<option value="Scissors">Scissors</option>
<option value="Check">Check</option>
</select>
<input type="submit" value="Play" name="dopost">
<input type="button" value="Logout" name="logout"></p>
</forms>
<pre>
<?php
foreach($rslt as $k => $v){
echo $v."\n";
}
?>
</pre>
</body>
</html>
这是它之前的模型控件:
<?php
$rslt=array("Please select a strategy and press Play.");
$names=array("Rock","Paper","Scissors");
if(!isset($_GET['name'])) die("Name parameter missing");
if(isset($_POST['logout'])){
header("Location: login.php");
return;
}
function play($h){
$c=$names[rand(0,2)];
if($h===$c) $r="Tie";
else if($h==="Rock" && $c==="Scissors") $r="You win.";
else if($h==="Scissors" && $c==="Paper") $r="You win.";
else if($h==="Paper" && $c==="Rock") $r="You win.";
else $r="You lose.";
return "Your Play=$h Computer Play=$c Result=$r";
}
if(isset($_POST['option'])){
if($_POST['option']==="Select") $rslt=array("You must select a strategy in order to play.");
else if($_POST['option']==="Check"){
}
else{
$rslt=array(play($_POST['option']));
}
}
?>
按下任一按钮as it shows here. 时我什么都没有,但源代码显示first php variables are being recognized。
【问题讨论】:
-
你必须在表单中添加一个动作
标签: php html forms post http-post