每次点击提交时都会触发我的if ifif语句,它只是特定的语句。我已经检查过堆栈的类似问题,但它们都与不触发的语句有关。我还试图多次验证我的表单,无论是对还是错,这些特定的表单都会触发:
用户名:strlen声明
密码:strlen声明
电子邮件:FILTER_VALIDATE_EMAIL
即使填写了所有字段,也会触发空检查。
任何帮助纠正这一点真的很感激。
//Spam Check
if($spam > 2){
$error .= '<div class="problem">Too many accounts have been created from this IP Address. Please contact us if you would like to create more.</div>';
}
//Username Check
if(!preg_match("/^[a-zA-Z0-9 ]*$/",$user)){
$error .= '<div class="problem">You may only use letters and numbers in your username.</div>';
}
elseif(strlen($user) < 3 OR strlen($user) > 20){
$error .= '<div class="problem">Please use an username between 3 and 20 characters.</div>';
}
elseif($taken > 0){
$error .= '<div class="problem">This username has already been taken. Please choose another.</div>';
}
//Password Check
if(!preg_match("/^[a-zA-Z0-9 ]*$/",$pass1)){
$error .= '<div class="problem">Do not use special characters in your password.</div>';
}
elseif(strlen($pass1) < 5 OR strlen($pass1) > 20){
$error .= '<div class="problem">Your password must be at least 5 characters and no more than 20.</div>';
}
elseif($pass1 != $pass2){
$error .= '<div class="problem">You did not confirm your passwords correctly. Please make sure they are the same.</div>';
}
//E-Mail Check
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$error .= '<div class="problem">The E-Mail Address entered was invalid. Please use another.</div>';
}
elseif(strlen($email) > 50){
$error .= '<div class="problem">This E-Mail Address is too large for us to store. Please use a different one.</div>';
}
//Empty Check
if(empty($user) OR empty($pass1) OR empty($pass2) OR empty($email)){
$error .= '<div class="problem">You need to fill out all fields to create an account.</div>';
}
//Variables
$user = mysqli_real_escape_string($_POST['username']);
$pass1 = mysqli_real_escape_string($_POST['pass1']);
$pass2 = mysqli_real_escape_string($_POST['pass2']);
$email = mysqli_real_escape_string($_POST['email']);
答案 0 :(得分:0)
你在POST数据上使用mysqli函数 - 你的变量不是来自SQL,是吗?使用trim()和strip_tags()或类似的东西来清理你的数据(但是要开始进行清理,并使用mysqli而不是mysql函数。)
对所有变量尝试这样的事情,看看你的IF语句是否开始正确评估。如果它们都是NULL,那么它们现在可能都返回false。
$user = strip_tags(trim($_POST['username']));