Re: How do I output error messages

From: Date: Tue, 21 Feb 2006 20:57:29 +0000
Subject: Re: How do I output error messages
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-230829@lists.php.net to get a copy of this message
On Tue, February 21, 2006 12:52 pm, Paul Goepfert wrote: $messages = array(); > if (isset($submit)) > { > //vaildation code Each invalid input adds another element to $messages array. //E.G.: if (!isset($_REQUEST['name'])) $messages[] = "Name is a required field."; > } > else > { if (count($messages)){ echo "<p class=\"error\">", implode("<br />\n", $messages), "</p>\n"; } > //webpage > } You still need to take care that the //webpage itself is not made insensible by the error conditions... In extreme cases, such as the database being down and there being no hope of the rest of the page being useful, I sometimes will do: if (!$connection){ head("Error"); //This prints out masthead/navbar etc $messages[] = "Unable to access database. Please try later."; echo "<p class=\"error\">", implode("<br />\n", $messages), "</p>\n"; foot(); //This closes all HTML tags from head() //both head and foot are defined in a single include file, //making it trivial to match up HTML open/close tags } It's not as "slick" as some CRM setups, but it's also not as cumbersome and over-engineered (imho). DSFDF -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#230829) next »