0

我正在尝试验证表单,并且只有在安全答案正确的情况下才能将表单的值插入到数据库中。但是当给出错误答案时,值会被插入。

if(empty($answer) && (!$answer == $sec_ans)) {
    echo "<div class='db_rp'>Error: You did not answer your security question</div>";
} else {

     $insert = "INSERT INTO laits SET 
     p_no = '{$new_pp}',
     r_number= '{$r_number}',
     memo = '{$memo}',
     user= '{$userid}',
     acc = '{$acc}'";

     if(!mysqli_query($conn, $insert)) {
     die('<div class="reply"> There was an error submtting your request ' . mysqli_error($conn)) . '</div>';
     }     
       else {
      header("location: tran_su.php"); 
       }
}
4

2 回答 2

1

您的代码需要这两个条件,并且至少应该是一个。

if(empty($answer) || ($answer != $sec_ans)) {
....
于 2013-09-15T00:27:47.740 回答
-1
if (empty($answer) || ($answer != $sec_ans)) {
于 2013-09-15T00:25:37.987 回答