PHP表单验证码

时间:2016-03-26 08:33:35

标签: php html forms

我仔细检查了所有这些代码,但仍然无法确定原因。错误是当我填写所有选项时,它仍显示“请填写所有字段”

<?php
if (!empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['password_again']) && !empty($_POST['gender']) && !empty($_POST['info']) ){
     $username = $_POST['username'];

}   
else{
    echo "You need to fill all fields";
}
?>


<!DOCTYPE HTML>
 <html>
<body>
<form method= "post">
<h2>Register</h2>
username:<input type ="text" name ="usename"/><br/>
password:<input type ="password" name ="password"/><br/>
password again:<input type ="password" name ="password_again"/><br/>
Gender: male<input type ="radio" value="male" name ="gender"/> female<input       type ="radio" value="female" name ="gender"/><br/>
Tell us about yourself:<br/>
<textarea name="info">
</textarea>
<br/>
<input type ="submit" value = "submit"/>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

字段的名称和php文件中的名称不一样。当您的名称为 usename 时,您正在检查字段用户名

更改此行

<input type ="text" name ="usename"/>

到此

<input type ="text" name ="username"/>

现在应该可以了。