Re: empty() problem

From: Date: Sun, 12 Dec 2004 15:12:34 +0000
Subject: Re: empty() problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-204108@lists.php.net to get a copy of this message
Ahmed Abdel-Aliem wrote:
Hi Group Members i have a problem with function empty() i use it to check if user entered the form fields and store it in array for example : if (empty($Game_rating)) $errors[] = "You didn't enter the Online Status for the Game."; the problem when the user enters 0 in the form field the empty function returns the error.
Is $Game_rating supposed to be an integer? If so, then make it one and check for <= to zero. if(!isset($_Game_rating) || (int)$Game_rating <= 0) { $errors[] = "You didn't enter the Online Status for the Game."; } Now you _know_ $Game_rating is an integer above zero and is safe to display and/or put into a query. Simply checking for if($Game_rating == '') will throw notices on some setups about an undefined variable (depending upon error_reporting level) and will allow text through when it's supposed to just be an integer. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#204108) next »