how can I check if any field is empty i tried this:

$x = $_POST['a'];
$y = $_POST['b'];
$z = $_POST['c'];

if($x or $y or $z == ""){echo "Please fill in all the fields";} 
else{
//rest of the code
}

but I allways receive the "Please fill in all the fields" message even when i fill in all the fields..

I also tried using the is_empty function but I got an undefined function error

Thanks!

Recommended Answers

All 4 Replies

You can use strlen() to check this.

if(strlen($x) ==0)
{
    echo "X is blank";
}

in your if statement

if($x or $y or $z == "")

it should be

if($x || $y || $z == "")
Member Avatar for diafol
if($x =="" || $y == "" || $z == "")

OR

if(empty($x) || empty($y) || empty($z))

However, empty is true if a variable is set to:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)

[from the php manual]

commented: thanks for the correction master ^_^ +2

in your if statement

if($x or $y or $z == "")

it should be

if($x || $y || $z == "")

Well i had tried using || before posting here and it didn't work

if($x =="" || $y == "" || $z == "")

OR

if(empty($x) || empty($y) || empty($z))

However, empty is true if a variable is set to:
"" (an empty string)
0 (0 as an integer)
"0" (0 as a string)

[from the php manual]

:o that might work, thanks! I will try it tomorrow when I am on my main PC

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.