2017-07-21 112 views
-3

我需要一些幫助與此應用程序從日誌應用程序中脫落

我無法得到正確的輸出。幫助將不勝感激

所以到目前爲止我的代碼是

<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

你缺少一個;在mybutton()之後,我想是$ GLOBALS你試圖調用的 –

回答

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> 
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; 

} 


} 




?> 
相關問題