嘿,我正在处理一个简单的注册表单,我已经对它进行了简单的测试。基本上我说如果用户名归档是空的,我们点击提交它将回显'所有提交的都是必需的'否则确定。我的代码看起来很好,否则我会疯了可以有人看看我谢谢你:)
代码:
<?php
//require 'core.inc.php';
if(isset($_POST['username'])&& isset($_POST['password']) && isset($_POST['passwordAgain'])&& isset($_POST['Firstname'])&& isset($_POST['Lastname'])){
$username = $_POST['username'];
$password = $_POST['password'];
$password_again = $_POST['passwordAgain'];
$Firstname = $_POST['Firstname'];
$Lastname = $_POST['Lastname'];
if(!empty($username)){
echo 'OK.';
}else{
echo 'fill in all details thank you';
}
}
?>
<form action="join.inc.php" method="POST">
Username: <input type="text" name="username" /><br />
Password: <input type="password" type="password" /><br />
Password Again: <input type="password" type="passwordAgain" /><br />
FirstName: <input type="text" name ="Firstname"/><br />
LastName: <input type="text" name ="Lastname" /><br />
<input type="submit" value="SUBMIT" />
</form>
答案 0 :(得分:4)
纠正这个:
Password: <input type="password" name="password" /><br />
Password Again: <input type="password" name="passwordAgain" /><br />
答案 1 :(得分:0)
您的问题出在您的HTML中:
Password: <input type="password" type="password" /><br />
Password Again: <input type="password" type="passwordAgain" /><br />
您指定的是两次类型字段,而不是名称字段。
答案 2 :(得分:0)
如何为提交按钮命名并尝试这样:
<input type="submit" name="sbmtBtn" value="SUBMIT" />
并提交部分:
if(isset($_POST['sbmtBtn']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$password_again = $_POST['passwordAgain'];
$Firstname = $_POST['Firstname'];
$Lastname = $_POST['Lastname'];
if($username && $password && $password_again && $Firstname && $Lastname))
{
echo 'OK.';
}
else
{
echo 'all fields are required.';
}
}