使用php将选定的无线电值输入下一页进行在线测试

使用php将选定的无线电值输入下一页进行在线测试,php,session,Php,Session,我正在开发在线测验系统。我想在完成考试后显示用户选择的答案和正确答案。请帮帮我 下面是我的代码问题。php代码 <?php require 'dataconnection.php'; $res = mysql_query("select * from questions where category_id=$category ORDER BY RAND() LIMIT 20") or die(mysql_error()); $rows = mysql_num_rows($res);

我正在开发在线测验系统。我想在完成考试后显示用户选择的答案和正确答案。请帮帮我

下面是我的代码问题。php代码

<?php 

require 'dataconnection.php';

$res = mysql_query("select * from questions where category_id=$category ORDER BY RAND() LIMIT 20") or die(mysql_error());
$rows = mysql_num_rows($res);

echo $rows;
$i=1;
while($result=mysql_fetch_assoc($res)){

   if($i==1){?>
        <div id='question<?php echo $i;?>' class='cont'>

           <p class='questions' id="qname<?php echo $i;?>"> <?php echo $i?>.<?php echo $result['Question'];?></p>
           <input type="radio" value="A" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $result['QNo'];?>'/><?php echo $result['Option A'];?>
           <br/>
           <input type="radio" value="B" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo  $result['QNo'];?>'/><?php echo $result['Option B'];?>
           <br/>
           <input type="radio" value="C" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $result['QNo'];?>'/><?php echo $result['Option C'];?>
           <br/>
           <input type="radio" value="D" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $result['QNo'];?>'/><?php echo $result['Option D'];?>
           <br/>
           <input type="radio" checked='checked' style='display:none' value="5" id='radio1_<?php echo $result['QNo'];?>' name=''/>                                                                      
           <br/> 

           <input type="hidden" id="offset" value='<?php echo $i+1; ?>' />
           <button id='next<?php echo $i;?>' class='next btn btn-success' type='button'>Next</button>


        </div>    

   <?php  }

   if($i<$rows){?>
       <div id='question<?php echo $i;?>' class='cont'>

           <p class='questions' id="qname<?php echo $i;?>"> <?php echo $i?>.<?php echo $result['Question'];?></p>
           <input type="radio" value="A" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $result['QNo'];?>'/><?php echo $result['Option A'];?>
           <br/>
           <input type="radio" value="B" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo  $result['QNo'];?>'/><?php echo $result['Option B'];?>
           <br/>
           <input type="radio" value="C" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $result['QNo'];?>'/><?php echo $result['Option C'];?>
           <br/>
           <input type="radio" value="D" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $result['QNo'];?>'/><?php echo $result['Option D'];?>
           <br/>
           <input type="radio" checked='checked' style='display:none' value="5" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $result['QNo'];?>'/>                                                                      
           <br/>
           <input type="hidden" id="offset" value='<?php echo $i+1; ?>' /> 
           <button id='pre<?php echo $i;?>' class='previous btn btn-success' type='button'>Previous</button> 

           <input type="hidden" id="offset" value='<?php echo $i+1; ?>' />  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
                 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

           <button id='next<?php echo $i;?>' class='next btn btn-success' type='button'>Next</button>


       </div>    

   <?php  }elseif($i==$rows){?>
       <div id='question<?php echo $i;?>' class='cont'>
           <p class='questions' id="qname<?php echo $i;?>"> <?php echo $i?>.<?php echo $result['Question'];?></p>
           <input type="radio" value="A" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo  $result['QNo'];?>'/><?php echo $result['Option A'];?>
           <br/>
           <input type="radio" value="B" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo  $result['QNo'];?>'/><?php echo $result['Option B'];?>
           <br/>
           <input type="radio" value="C" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo  $result['QNo'];?>'/><?php echo $result['Option C'];?>
           <br/>
           <input type="radio" value="D" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo  $result['QNo'];?>'/><?php echo $result['Option D'];?>
           <br/>
           <input type="radio" checked='checked' style='display:none' value="5" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $result['QNo'];?>'/>                                                                      
           <br/>              

           <input type="hidden" id="offset" value='<?php echo $i+1; ?>' /> 
           <button id='pre<?php echo $i;?>' class='previous btn btn-success' type='button'>Previous</button>
           <button id='next<?php echo $i;?>' class='next btn btn-success' type='submit'>Finish</button>
       </div>
   <?php } $i++;   $_SESSION['questions'][]=$result;
}
?>













我将所有问题存储在会话变量中,并在下一页显示。但我不知道如何获得选中的单选按钮值

Result.php

<?php
session_start();
$_SESSION['questions'];


for($i=0;$i<20;$i++) { ?>
    <div id='questions'  class='container-fluid cont'>

        <p class='questions' id="qname<?php echo $i;?>"> <?php echo $i+1?>.<?php echo $_SESSION['questions'][$i]['Question'];?></p>
        <input type="radio" value="A" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $_SESSION['questions'][$i]['QNo'];?>'/><?php echo $_SESSION['questions'][$i]['Option A'];?>
        <br/>
        <input type="radio" value="B" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $_SESSION['questions'][$i]['QNo'];;?>'/><?php echo $_SESSION['questions'][$i]['Option B'];?>
        <br/>
        <input type="radio" value="C" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $_SESSION['questions'][$i]['QNo'];;?>'/><?php echo $_SESSION['questions'][$i]['Option C'];?>
        <br/>
        <input type="radio" value="D" id='radio1_<?php echo $result['QNo'];?>' name='<?php echo $_SESSION['questions'][$i]['QNo'];;?>'/><?php echo $_SESSION['questions'][$i]['Option D'];?>
        <br/>
        <input type="radio" checked='checked' style='display:none' value="5" id='radio1_<?php echo $_SESSION['questions'][$i]['QNo'];;?>' name='<?php echo $result['QNo'];?>'/>                                                                      
        <br/> 
    </div>

<?php } ?>