PHP表单未验证

时间:2013-09-15 00:22:52

标签: php forms

尝试验证表单时,如果安全性答案正确,则只能将表单的值插入到数据库中。但是,如果给出了错误的答案,则会插入值。

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"); 
       }
}

2 个答案:

答案 0 :(得分:1)

您的代码需要两个条件,并且应该只有一个条件。

if(empty($answer) || ($answer != $sec_ans)) {
....

答案 1 :(得分:-1)

if (empty($answer) || ($answer != $sec_ans)) {