如何检查表单中的任何字段在php中是否为空 [英] How to check if any fields in a form are empty in php

查看:75
本文介绍了如何检查表单中的任何字段在php中是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我提交我的表单中的东西,我想检查是否有任何字段是空的。到目前为止,我有什么不工作

  $ firstname = $ _POST ['firstname']; 
$ lastname = $ _POST ['lastname'];
$ username = $ _POST ['username'];
$ password = $ _POST ['password'];
$ passwordconf = $ _POST ['passwordconf'];
$ email = $ _POST ['email'];
$ securityq = $ _POST ['securityq'];
$ qanswer = $ _POST ['qanswer']; $($ firstname)|| empty($ lastname)|| empty($ username)|| empty($ password)|| empty($ passwordconf)|| empty($ email)

if || empty($ securityq)|| empty($ qanswer))
{
echo你没有填写必填字段。

code $ <$ $ p

和表格

 < form name =registrationformaction =register.php> 
名字:< input type =textname =firstname>
姓氏:< input type =textname =lastname>
电子邮件地址:< input type =textname =email>
用户名:< input type =textname =username>
密码:< input type =passwordname =password>
确认密码:< input type =passwordname =passwordconf>
安全问题:< input type =textname =securityq>
答案:< input type =textname =qanswer>
< input type =submitname =submitvalue =Register>
< / form>

以及heres登录页面(如果有帮助) http://www.myjournal.tk/register.html

解决方案

您的表单缺少方法...

 < form name =registrationformaction =register。 phpmethod =post> // here 

anywyas检查发布的数据,您可以使用 isset() ..


确定是否设置了变量并且不为NULL




  if(!isset($ firstname )|| trim($ firstname)=='')
{
echo你没有填写必填字段。
}


whenever I submit something in my form i want to check if any of the fields are empty. So far what I have is not working

$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.";
}

and the form

<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>

and heres the registation page if it helps http://www.myjournal.tk/register.html

解决方案

your form is missing the method...

<form name="registrationform" action="register.php" method="post"> //here

anywyas to check the posted data u can use isset()..

Determine if a variable is set and is not NULL

if(!isset($firstname) || trim($firstname) == '')
{
   echo "You did not fill out the required fields.";
}

这篇关于如何检查表单中的任何字段在php中是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆