Implementing quiz using php and mysql

My PHP function does not read the value attribute of the radio buttons and returns them as empty valus as shown in the codes below:

Form:

    <?php 
      require('connection.php');

      $quiz="SELECT * from testquiz";
      $display = mysqli_query($conn, $quiz);
      while($q= mysqli_fetch_assoc($display)){
          $i=$q['id']
          ?>
            <?php echo "Q.".$q['id'];?>&nbsp;<?php echo $q['question']?><br>
            <form action="quiztest.php" method="post">

            A.<input type="radio" name="op<?=$i?>" value="a"/><?php echo htmlentities ($q['option1']);?><br>

            B.<input type="radio" name="op<?=$i?>" value="b"/><?php echo htmlentities ($q['option2']);?><br>

            C.<input type="radio" name="op<?=$i?>" value="c"/><?php echo htmlentities ($q['option3']);?><br>

            D.<input type="radio" name="op<?=$i?>" value="d"/><?php echo htmlentities ($q['option4']);?><br><br>

    <?php
    $i=$i+1;
    }?>

        <input type="submit" name="quiz" value="Submit"/>
        </form>

PHP functions:

<?php
 require('connection.php');

   if(isset($_POST['quiz'])){
      $query="SELECT * FROM testquiz ";
      $count=0;
      $total=2;
      $result=mysqli_query($conn,$query);

      while($row=mysqli_fetch_array($result)){
         $i=$row['id'];
         if(empty($_POST['op'])){
            $_POST['op']='e';
         }

         if($_POST['op']==$row['correct']){
            $count=$count+1;
         }
         echo $i,$_POST['op'],"&nbsp;";
         $i=$i+1;
      }
      echo "<br>";
      echo (($count/$total)*100),"%";
   }
?>

The output observed by after submit:
image

2 Likes