0

正如标题所说,我正在构建一个注册页面,我正在按照教程并构建代码,并且由于某种原因而不是打印错误,它只是在 url 中发布,这是我的代码。

    <?php include ("core/init.php"); ?>
<?php include ("includes/overall/header.php"); 

if (empty($_POST) === false) {
$required_fields = array('username', 'password', 'password_again', 'email');
foreach($_POST as $key=>$value) {
    if (empty($value) && in_array($key, $required_fields) === true) {
        $errors[] = 'Fields marked with an * are required';
        break 1;
    }

}


}
print_r($errors);
?>
<h1>Register</h1>
<form action="" method"post">
<ul>
    <li>
        Username*:<br>
        <input type="text" name="username">
    </li>
    <li>
        Password*:<br>
        <input type="password" name="password">
    </li>
    <li>
        Password Again*:<br>
        <input type="password" name="password_again">
    </li>
    <li>
        E-mail*:<br>
        <input type="text" name="email">
    </li>
    <li>
        <input type="submit" value="Register">
    </li>
</ul>

</form>
<?php include ("includes/overall/footer.php") ; ?>
4

1 回答 1

0
<form action="" method"post">

应该

<form action="" method="post">

您的表单默认为,GET因为它没有正确表示方法,因此 $_POST 为空,因此您的 foreach 没有任何要检查的内容。

于 2013-07-10T03:25:35.007 回答