faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input : Validating Data

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

Why do my errors show up before the form is even filled in?

Jun 23rd, 2004 09:48
Philip Olson, Rick James,


Use a function (technically they are language constructs but who's 
counting) to check if a variable is set or not, for example:
  // Don't do this, E_NOTICE level errors will exist if $foo
  // is not set
  if ($foo) {
  // Do this instead, or use empty($foo)
  if (isset($foo) {
Notice the difference here.  Using isset() and empty() will not create 
E_NOTICE level errors as you're not using the undefined variables but 
rather you're "checking" them.
On a related note, you _could_ lower your error reporting level to 
hide E_NOTICE level errors but this is NOT recommended as all good 
programmers code at level E_ALL!
See the following manual pages for details:
  http://www.php.net/isset
  http://www.php.net/empty
  http://www.php.net/error_reporting