0
       <?php
      $score=0;
      $i=0;  
      function icremm($i) {
        $Question1=array( "answer1aa","answer1b","answer1c","answer1d");
     $Question2=array( "answer2a","answer2bb","answer2c","answer2d");
     $Question3=array( "answer3a","answer3b","answer3c","answer3dd ");
     $allquest=(array($Question1,$Question2,$Question3));

   $rand1=$allquest[$i];
    ?>
    <form method="POST">
    <input  type="submit"  name="1b"   value="<?php echo $rand1[0] ?>"/>
    <input  type="submit"   name="2b"  value="<?php echo $rand1[1] ?>" />
     <input  type="submit"   name="3b"  value=" <?php echo $rand1[2] ?>" />
    <input  type="submit"   name="4b"   value="<?php echo $rand1[3] ?>"  />
    </form>
    <?php 
     echo "<br>";
   global $score;
    echo $score;
    echo "<br>";
     echo "<br>";
      global $i;
     echo $i;
    }  
    icremm($i);

       if  (isset($_POST["1b"]) )  {
        $score+=5; 
         $i++;

       goto L1;  
   }  

  if( $i==0 && isset($_POST["2b"]) || $i==0 &&  isset($_POST["3b"]) ||$i==0 &&  isset($_POST["4b"]) )  {
   header("Location: lost.php");
    }
L1:{
    @ob_end_clean(); 
    icremm($i);


 if  (isset($_POST["2b"]) )  {
        $score+=5;
         $i++;
@ob_end_clean();         
     echo"you won";

    }   
    } 

    ?>
  1. i try to make my first game like "who wants to be a millionaire" and when i answer first question and go to L1 the first statement(//if( $i==0 && isset($_POST["2b"]) || $i==0 && //isset($_POST["3b"]) ||$i==0 && isset($_POST["4b"]) ) { // header("Location: lost.php");) still works

  2. but i want to L1 statement to work

  • 1
    http://php.net/manual/en/images/0baa1b9fae6aec55bbb73037f3016001-xkcd-goto.png You should work on your indentations and use functions not `goto`. – chris85 Jun 03 '17 at 12:21
  • first statement don't work as you want, right now work like this: `if( $i==0 && (isset($_POST["2b"]) || $i==0) && (isset($_POST["3b"]) || $i==0) && isset($_POST["4b"]) )` also follow chris85 recommendation – Kazz Jun 03 '17 at 12:31
  • also `$i` and `$score` is not stored anywhere between requests, if you submit form by `1b` button, you should actually get to L1, which will be under previous form generated from `$i = 0` because there is no `ob_start` – Kazz Jun 03 '17 at 12:40
  • Using `goto` is a really bad programmig practice - [see for instance](https://stackoverflow.com/questions/1900017/is-goto-in-php-evil/1900055) – Picard Jun 03 '17 at 15:10
  • @chris85 can you be more specific,please. – Genrijs Larsons Jun 11 '17 at 13:06

0 Answers0