[TriLUG] PHP is_null is driving me in_sane
Greg Brown
greg at airlannetworks.com
Tue Jan 25 09:30:23 EST 2005
You're right! Yo da man!
Greg
On Jan 25, 2005, at 9:24 AM, David Rasch wrote:
> 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
>>
> --
> 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
More information about the TriLUG
mailing list