I have a program that accepts 5 variables from a HTML form and the first thing I do is check to see if all the fields have some data in them. If not, the user gets a message that not all the fields are completed. Two of the fields are for text entry and the other three are for single digit numbers (one for each text field box).
I check them something like this:
?>
if( empty($field1) || empty($field2) || empty($field3) || empty($field4)
{
echo "You have not completed all the fields";
}
else
{ execute the rest of the code
}
One problem is that if a person enters "0" (zero) in one of the number fields (which should be a valid entry for my purposes) The empty($field) evaluates to true as if the field is empty.
First question: Is there a way to check if a field is empty or not, but that will consider "0" as not empty?
Second question: Is this the best way to check if the fields all have data entered?
Thanks for any insights