PHP和mySQL Radio Buttons中的测验不起作用

时间:2015-04-20 16:37:29

标签: php html mysql radio-button

我正在尝试在PHP和mySQL中进行一个非常基本的测验。

基本上,我有一个用户"发布测验"页面,允许用户发布3个问题,包括3个选项和一个解决方案。如果用户按下的单选按钮的值等于问题的答案(这是在"后测验"页面中进行的话),那么它将返回文本说他们说得对,其他明智的会说这是错的。

我的问题:

我已经完成了一切工作吧:当我点击表格中的一个单选按钮时,他们似乎都发布了相同的条件

也许我的代码根本就是错误的而且我没有看到它,但我已经在这一周了,有人可以找到我的错误吗?

测验页面:

代码说明每个按钮等于什么,

$_POST['q2o1'] = $tresult['q2_opt1'];
$_POST['q2o2'] = $tresult['q2_opt2'];
$_POST['q2o3'] = $tresult['q2_opt3'];
$q2answer = $tresult['q2answer'];
$question2 = $tresult['question2'];

$_POST['q3o1'] = $tresult['q3_opt1'];
$_POST['q3o2'] = $tresult['q3_opt2'];
$_POST['q3o3'] = $tresult['q3_opt3'];
$q1answer = $tresult['q1answer'];
$question1 = $tresult['question1'];

$_POST['q1o1'] = $tresult['q1_opt1'];
$_POST['q1o2'] = $tresult['q1_opt2'];
$_POST['q1o3'] = $tresult['q1_opt3'];
$q3answer = $tresult['q3answer'];
$question3 = $tresult['question3'];

$q1_opt1 = $_POST['q1o1'];
$q1_opt2 = $_POST['q1o2'];
$q1_opt3 = $_POST['q1o3'];
$q2_opt1 = $_POST['q2o1'];
$q2_opt2 = $_POST['q2o2'];
$q2_opt3 = $_POST['q2o3'];
$q3_opt1 = $_POST['q3o1'];
$q3_opt2 = $_POST['q3o2'];
$q3_opt3 = $_POST['q3o3'];

单选按钮和问题布局的HTML代码:

<?php echo '<form action="quiz.php?id='.$id.'" method ="post">';?>
    <h3 id="question2"><u>Question 1: </u></h3><p> <i><?php echo $question1;?></i></p>
    <br>
    <p>A: <?php echo $q1_opt1;?></p>
    <p>B: <?php echo $q1_opt2;?></p>
    <p>C: <?php echo $q1_opt3;?></p>
    <br>
    <div class="btn-group" data-toggle="buttons">
      <label class="btn btn-primary">
        <input type="radio" name="q1o1" value =<?php echo "".$q1o1."";?> id="option1" autocomplete="off"> A
      </label>
      <label class="btn btn-primary">
        <input type="radio" name="q1o2" value =<?php echo "".$q1o2."";?>id="option2" autocomplete="off"> B
      </label>
      <label class="btn btn-primary">
        <input type="radio" name="q1o3" value =<?php echo "".$q1o3."";?> id="option3" autocomplete="off"> C
      </label>
    </div>
<button type="submit" name ="submitquiz" class="btn btn-success">Submit!
          <span class="glyphicon glyphicon-ok"></span></button>

PHP说明是否为每个按钮提交了POST:

<?php
if(isset($_POST['submitquiz'])){
  if(isset($_POST['q1o1']) && $_POST['q1o1'] == $q1answer ){
    $c1= '<p><font color="#62FD01">That is the correct answer!</font></p>';
  } else{
     $w1= '<p> <font color="red">That is the wrong answer!</font></p>';
  }if(isset($_POST['q1o2']) && $_POST['q1o2'] == $q1answer ){
    $c1= '<p><font color="#62FD01">That is the correct answer!</font></p>';
  } else{
     $w1= '<p> <font color="red">That is the wrong answer!</font></p>';
  }
if(isset($_POST['q1o3']) && $_POST['q1o3'] == $q1answer ){
    $c1= '<p><font color="#62FD01">That is the correct answer!</font></p>';
  } else{
     $w1= '<p> <font color="red">That is the wrong answer!</font></p>';
  }
}
else {
  echo '<p><font color="orange">You did not answer this question</font></p>';
}
?>
<?php
if(isset($w1)){
 echo $w1; 
}else{
 echo $c1; 
}


?>

0 个答案:

没有答案