我正在尝试创建一个基本的注册脚本。将所有表格留空时,我会收到一条消息,说我没有使用有效的电子邮件地址,但我希望它告诉我没有输入任何数据,如果任何表格留空,请执行此操作。逻辑似乎不正确,它可能是一个小问题,但我找不到它。
主页.php
<html>
<head>
</head>
<body>
<?php
require 'functions.php';
registration_form();
?>
</body>
</html>
函数.php
function registration_form() {
echo '<form id="register" action="register.php" method="post">';
echo '<fieldset>';
echo '<legend>Register</legend>';
echo '<input type="hidden" name="submitted" id="submitted" value="1" /></br>';
echo '<label for="email">Email Address:</label></br>';
echo '<input type="text" name="email" id="email" maxlength="100" /> </br>';
echo '<label for="password">Password:</label></br>';
echo '<input type="password" name="password" id="password" maxlength="60" /></br>';
echo '<label for="confirmpassword">Confirm Password:</label></br>';
echo '<input type="password" name="confirmpassword" id="confirmpassword" maxlength="60" /></br>';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</fieldset>';
echo '</form>';
}
function validate_registration($password, $confirmpassword, $email) {
if ((!isset($email)) || (!isset($password)) || (!isset($confirmpassword))) {
registration_form();
echo "Please enter the required information:";
}
elseif ((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($password == $confirmpassword)) {
echo "You have registered with: $email";
}
elseif ((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($password !== $confirmpassword)) {
registration_form();
echo "Your password does not match!";
}
else {
registration_form();
echo "You have not entered a valid email address!";
}
}
注册.php
require 'functions.php';
$email = $_POST['email'];
$password = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
validate_registration($password, $confirmpassword, $email);