[TriLUG] PHP is_null is driving me in_sane
David Rasch
rasch at raschnet.com
Tue Jan 25 09:24:10 EST 2005
You really want to use "empty" since a blank submission of a field does
not set it to "null", but rather doesn't set it. So you could change
your conditional "is_null" to "empty" and you should get the desired
result.
David
On Tue, Jan 25, 2005 at 09:20:04AM -0500, Greg Brown <gregbrown at mindspring.com> wrote:
> Grrr.... okay, I am trying a simple function in PHP. I am passing four
> variables, first name, last name, e-mail, and phone number to the PHP
> script. The PHP function is_null simply refuses to figure out that a
> required field, $firstName is empty. So, is there a better way to do
> this? Say, perhaps, a regular expression that figures out there are no
> alphanumeric characters or something?
>
> Here's a code snippet:
>
> <?php
>
> /* now let's get the variables passed to the script */
> $firstName=trim($HTTP_POST_VARS['fname']);
> $lastName=trim($HTTP_POST_VARS['lname']);
> $email=trim($HTTP_POST_VARS['email']);
> $phone=trim($HTTP_POST_VARS['phone']);
>
> // echo "<P>$firstName<br>";
> // echo "$lastName<br>";
> // echo "$email<br>";
> // echo "$phone<br>";
>
> /* now let's test to see if anything was left empty that
> should not have been */
>
> /* create a function to handle the error message */
> function writeError($a) {
>
> echo "It appears you have forgotten to enter the
> required field of: $a<b
> r>";
> echo "Please re-enter the data<p>";
>
> }
>
> if (is_null($firstName)) {
>
> $errorReturn = writeError("First Name");
>
> }
>
> else {
>
> //code processing goes here
>
> }
>
> ?>
>
> --
> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ : http://trilug.org/faq/
> TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> TriLUG PGP Keyring : http://trilug.org/~chrish/trilug.asc
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://www.trilug.org/pipermail/trilug/attachments/20050125/4b7928f8/attachment.pgp>
More information about the TriLUG
mailing list