[TriLUG] PHP is_null is driving me in_sane

Greg Brown gregbrown at mindspring.com
Tue Jan 25 09:20:04 EST 2005


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

         }

?>




More information about the TriLUG mailing list