当答案正确时返回false,如何修复php中的代码?

时间:2016-05-08 09:06:04

标签: php

当答案正确时如何制作一条消息,表明答案是正确的?                                                                                             这是我的尝试>我尝试制作(if)但是当答案正确时返回false>>如何解决这个问题                                                                                                      请帮助!!!



<table dir="rtl"style="margin-right: 10px;" id="rounded-corner" summary="2007 Major IT Companies' Profit" style="margin-left:150px;">
    <thead>
    </thead>

    <tbody>
	
<?php

$query_run=mysql_query("select * from questions ORDER BY RAND() LIMIT 5");

 while($row=mysql_fetch_array($query_run))
        {
         $question = $row['question']; 
		 $ans = $row['ans'];
		 $anstwo = $row['anstwo'];
		 $correct_ans = $row['correct_ans'];

?>

    <tr> 
         <th  colspan="3"width="211" class="rounded" scope="col">السؤال</th>          
	  </tr>         
		<tr>
		  <?php
		      
echo"<tr><td> <img src=question/$question width=100 hieght=100></td></tr>";
echo"<tr><td><label>
  <input type=\"radio\" name=\"fb\" value=\"small\" /><img src=question/$ans width=100 hieght=100></label></td><td><label>
  <input type=\"radio\" name=\"fb\" value=\"small\" /><img src=question/$anstwo width=100 hieght=100></label></td><td><label>
  <input type=\"radio\" name=\"fb\" value=\"$correct_ans\" /><img src=question/$correct_ans width=100 hieght=100></label></td</tr><br>";
 
  ?>  
</tr>
<?php
 }
if (isset($_POST['submit'])) {   
   $value = $_POST;

    if ($value == "$correct_ans")
        echo "THAT ANSWER IS CORRECT";
    else
        echo "THAT ANSWER IS WRONG!";}
 ?>

    </tbody>
</table>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

if ($value == "$correct_ans")
        echo "THAT ANSWER IS CORRECT";
    else
        echo "THAT ANSWER IS WRONG!";}

应该是

if ($value == $correct_ans)
{
        echo "THAT ANSWER IS CORRECT";
}else
{
       echo "THAT ANSWER IS WRONG!";
}
你发布的“$ correct_ans”字符串不是变量。