0

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!

Edited by terabyte: n/a

4
Contributors
4
Replies
13
Views
7 Years
Discussion Span
Last Post by terabyte
2
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]

Edited by diafol: n/a

Votes + Comments
thanks for the correction master ^_^
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.