私は登録フォームを持っていますが、if文がすべて動作しているわけではありません。どうすればいいのですか?PHPでフォームの検証が動作しないすべてのifステートメント(デバッグヘルプ)
$password = ""; //Password
$password2 = ""; //COnfirm Password
//Pass
$password = strip_tags($_POST['reg_password']); //Remove html tags
$password2 = strip_tags($_POST['reg_password2']); //Remove html tags
//This if is working and return error
if($password != $password2) {
array_push($error_array, 'Your passwords do not match');
}
else{
//This one is working as well
if(preg_match('/[^A-Za-z0-9]/', $password)){
array_push($error_array, 'Special characters like "£%^*() are not allowed');
}
}
// I have the problem with this one. If user put 3 chars i don't get the error messages
// The form is not submitting but the error messages are not displayed
if(strlen($password) > 20 || strlen($password) < 5){
array_push($error_array, 'Your password must be between 5 and 20 characters');
}
if(empty($error_array)){
$password = md5($password); //Encrypt pass before send to db
<div class="form-group">
<label class="sr-only" for="reg_password2">Confirm Password</label>
<input type="password" name="reg_password2" placeholder="Password..." class="form-password form-control" id="reg_password2">
<span id="errorPassword2" class="text-danger"></span>
<?php if(in_array('Your passwords do not match', $error_array))
echo '<span id="errorPass" class="text-danger">Your passwords do not match</span>';
else if(in_array('Special characters like "£%^*() are not allowed', $error_array))
echo '<span id="errorPass" class="text-danger">Special characters like "£%^*() are not allowed</span>';
else if(in_array('Your password must be between 5 and 20 character', $error_array))
echo '<span id="errorPass" class="text-danger">Your password must be between 5 and 20 character</span>';
?>
</div>
特定のifオプション以外はすべて正常に動作しています。しかし、ユーザーが5〜20文字の制限内でパスを入れた場合、登録に問題はありません。
コードをテストしました。すべてがうまく見える http://sandbox.onlinephpfunctions.com/code/9ae4124447b43479d39b74d648dfabc685682005 – Rulisp
だから、 'var_dump(strlen($ password))' –
観察; $ error_arrayを初期化していません。 phpクローズタグは、次の文の後にmisedされます。if(empty($ error_array)){$ password = md5($ password);いずれかの閉鎖する必要がありますか、PHP変数の1つであなたのマークアップをconcatinateする必要があります – siva