每当我在表单中提交某些内容时,我想检查是否有任何字段为空.到目前为止,我所拥有的不起作用
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
$passwordconf = $_POST['passwordconf'];
$email = $_POST['email'];
$securityq = $_POST['securityq'];
$qanswer = $_POST['qanswer'];
if(empty($firstname) || empty($lastname) || empty($username) || empty($password) || empty($passwordconf) || empty($email) || empty($securityq) || empty($qanswer))
{
echo "You did not fill out the required fields.";
}
Run Code Online (Sandbox Code Playgroud)
和形式
<form name="registrationform" action="register.php">
First Name:<input type="text" name="firstname">
Last Name:<input type="text" name="lastname">
Email:<input type="text" name="email">
Username:<input type="text" name="username">
Password:<input type="password" name="password">
Confirm Password:<input type="password" name="passwordconf">
Security Question:<input type="text" name="securityq">
Answer:<input type="text" name="qanswer">
<input type="submit" name="submit" value="Register">
</form>
Run Code Online (Sandbox Code Playgroud)
如果有帮助http://www.myjournal.tk/register.html,请注册登记页面
bip*_*pen 15
你的表格缺少方法......
<form name="registrationform" action="register.php" method="post"> //here
Run Code Online (Sandbox Code Playgroud)
anywyas检查发布的数据你可以使用isset() ..
确定变量是否已设置且不为NULL
if(!isset($firstname) || trim($firstname) == '')
{
echo "You did not fill out the required fields.";
}
Run Code Online (Sandbox Code Playgroud)