首页 > 解决方案 > PHP 空用户名/密码输入

问题描述

我是 PHP 新手,所以我显然不擅长它。我想要做的是给用户一个错误,如果他们点击提交而不填写输入(名称/用户名/密码)这是我到目前为止所做的:

$fullname = ($_POST['fullname']);
$username = ($_POST['username']);
$password = ($_POST['password']);
if(empty($fullname)){
echo ('Please fill the blank spaces');
}

(不确定 echo 是一个很好的警报代码)

的HTML:

<article>
    <form id="signform" method="post" action="signup.php" autocomplete="off">
        <input name="fullname" placeholder="Your FullName">
        <input name="username" placeholder="UserName">
        <input name="password" type="password" placeholder="Password">
        <input class="Submit" type="button"  onclick="location.href='index.html';" value="Signup" />

    </form>
</article>

因此,如果我不填写任何我可以按提交和注册的输入,我不会做任何我不想发生的事情。

标签: html

解决方案


请使用type="submit"for 按钮并在 php 中验证后重定向到所需页面。

我建议你像这样使用:

<article>
    <form id="signform" method="post" action="signup.php" autocomplete="off">
        <input name="fullname" placeholder="Your FullName">
        <input name="username" placeholder="UserName">
        <input name="password" type="password" placeholder="Password">
        <input class="Submit" type="submit" value="Signup" />

    </form>
</article>

推荐阅读