2016-05-08 41 views
-1

怎样才能使答案正确时出现一条消息,答案是正确的? 这是我的尝试>我尝试使(if),但当答案正确时返回false >>如何解决此问题 请帮助!!!回答错误,当答案是正确的,如何解决在PHP代码?

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

 
    <tbody> 
 
\t 
 
<?php 
 

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

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

 
?> 
 

 
    <tr> 
 
     <th colspan="3"width="211" class="rounded" scope="col">السؤال</th>   
 
\t </tr>   
 
\t \t <tr> 
 
\t \t <?php 
 
\t \t  
 
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>

回答

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” 为您发布的是一个字符串不是一个变量。

+0

no does not work :(:( – mona

+0

你可以var_dump($ value)并查看它返回的内容吗? – azdonald