简体   繁体   English

PHP表单未通过验证

[英]PHP Form not validating

Am trying to validate a form and the values of the form can only be inserted into the database if the security answer is correct.Yet the values gets inserted when a wrong answer is given. 我正在尝试验证表单,并且只有在安全答案正确的情况下,才能将表单的值插入数据库中。但是,当给出错误答案时,将插入值。

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

Your code is requiring both conditions and should be only one as a minimum. 您的代码要求同时满足两个条件,并且至少应为一个。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM