Checking is field is empty

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mr.stana
Forum Newbie
Posts: 2
Joined: Wed Mar 23, 2011 2:51 pm

Checking is field is empty

Post by mr.stana »

HI,

im trying to check whether fields on my html page are empty. If they are i want a message to appear saying "youve not filled in all fields...etc." if they have filled it in then carry out the php. the code i have is:

Code: Select all

else if(is_null($firstname) || is_null($surname) || is_null($line1) || is_null($line2)|| is_null($country) || is_null($postcode) || is_null($telephonenumber) || is_null($cardhldname) || is_null($cardnumber) || is_null($country) || is_null($postcode) || is_null($telephonenumber) || is_null($cardhldname) || is_null($cardType) || is_null($securitynumber))
{
print ("Please make sure that all your fields have been filled in. Thank You.");
}

else{

do this code....

}
This code doesnt print the error if they leave the fields empty please advise!

Thanks,

Mike :) :banghead:
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Checking is field is empty

Post by AbraCadaver »

Empty is not the same as null. Use:

Code: Select all

if(empty($firstname))
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
foxmahesh
Forum Newbie
Posts: 5
Joined: Thu Mar 31, 2011 8:34 am

Re: Checking is field is empty

Post by foxmahesh »

use empty function instead of is_null
Post Reply