我需要一些关于此应用程序的帮助
我无法获得正确的输出。帮助将不胜感激
所以到目前为止我的代码是
<html>
<head>
</head>
<body>
<form action="" method="POST">
<input type="submit" name="step" value="take step">
</form>
<?php
$step = 0;
function mybutton() {
}
if(array_key_exists('step',$_POST)) {
$x = rand(0,1);
mybutton()
if($x == 1) {
GLOBAL['step'] = (GLOBAL['step'] + $x);
echo"you took a step forwards" .$step;
} else {
GLOBAL['step'] = (GLOBAL['step'] - $x);
echo"you took a step backwards" .$step;
}
}
?>
</body>
</html>
答案 0 :(得分:0)
打开你的PHP错误。您的脚本中存在语法错误。 这是有效的scrpit
<html>
<head>
</head>
<body>
<form action="" method="POST">
<input type="submit" name="step" value="take step">
</form>
<?php
$step = 0;
function mybutton() {
}
if(array_key_exists('step',$_POST)){
$x = rand(0,1);
mybutton();
if($x == 1)
{
$GLOBALS['step'] = ($GLOBALS['step'] + $x);
echo"you took a step forwards" .$step;
}
else
{
$GLOBALS['step'] = ($GLOBALS['step'] - $x);
echo"you took a step backwards" .$step;
}
}
?>
答案 1 :(得分:0)
你走在正确的轨道上!但是你有很多错误,而且你真的不需要这个功能
<html>
<head>
</head>
<body>
<?php
if (!isset($_POST['position'])){$position=0;}else{$position=$_POST['position'];}
if (!isset($_POST['history'])){$history="Starting your log adventure<br />";}else{$history=$_POST['history'];}
if(isset($_POST['step'])){
$x = rand(0,1);
if($x == 1){
$position++;
$history .= "<br />You took a step forwards" .$step;
}else{
$position--;
$history .= "<br />You took a step backwards" .$step;
}
if ($position<0||$position>7){
$history .= "<br />Sorry you just falled out the log!";
}
echo $history;
}
?>
<form method="post">
<input type="submit" name="step" value="take step">
<input type="hidden" name="position" value="<?=$position?>">
<input type="hidden" name="history" value="<?=$history?>">
</form>
</body>
</html>