php中的电子邮件验证

the*_*tro 3 html php sql email-validation

我正在尝试将我的用户名验证为电子邮件地址,但PHP不允许我这样做!这有什么不对?

//This checks if all the fields are filled or not
if (!empty($_POST['username']) || 
!empty($_POST['password']) ||
!empty($_POST['repassword']) || 
!empty($_POST['user_firstname']) ||
!empty($_POST['user_lastname']) ){
header('Location: register.php?msg=You didn\'t complete all of the required fields');
}

if (filter_var($_POST['username'], FILTER_VALIDATE_EMAIL) === false){
$errors[] = 'The email address you entered is not valid';
}
Run Code Online (Sandbox Code Playgroud)

这是我在register.php中使用的表单

<form action="createuser.php" method="post" name="registration_form" id="registration_form">
<label>Email</label>
<input name="username" type="text" id="username" size="50" maxlength="50" /><br />
Run Code Online (Sandbox Code Playgroud)

Mar*_*c B 5

错字?

header('Location: register.php?msg=You didn't complete all of the required fields');
                                           ^---unescaped embedded quote
Run Code Online (Sandbox Code Playgroud)

你的空逻辑也有问题.您正在检查是否有任何字段不是空的(例如填写完毕),然后抱怨它们没有填写.删除!以反转逻辑.

if (empty(...) || empty(...) || etc...)
Run Code Online (Sandbox Code Playgroud)