I need some help with this application

I am not able to get the right output. help would be appreciated

so my code so far is

<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>
    
you are missing a ; after mybutton(), i think is $GLOBALS what you try to call – caryarit ferrer 4 hours ago

2 Answers 2

You are on the right track! but you have a lot of errors and you don't really need a function for this

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

turn your PHP error on. You have syntax errors in your script. Here is the valid 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; 

}


}




?>