[FX.php List] Snippet: Displaying Error Code Messages

Jonathan Schwartz jonathan at exit445.com
Mon Mar 19 08:36:53 MDT 2007


Hi Folks,

Wanted to offer up a simple little snippet that I created today to 
help with error reporting.  Experienced fx.php users may already be 
using this technique....so this is for the beginners/intermediate 
fx.php users.

Up to this time, I have been using the FMErrors.php file as a simple 
reference tool to look up the meaning of error codes thrown by 
FMP/fx.php.  The file is buried deep in the FX folder. That gets 
tired after the 1,000th time.  On my last iteration, I realized that 
the file is actually an array: the error number is the key and the 
error phrase is the value.  Now that I am past my array-phobia, the 
answer seems clear. By simply requesting the value associated with 
the current error number (key), the error phrase can easily be 
displayed, like this:

include(FMErrors.php);
<snip>
if($searchResult['errorCode'] != '0' && $searchResult['errorCode'] != '401')
{
$msg = 'Oops! Your search didn\'t return any results due to a 
problem: Error#'.$searchResult['errorCode']. ' 
'.$errorsList[$searchResult['errorCode']];
}
...and then display the $msg where appropriate.


In this case, I have assumed that all errors other than  "0" (No 
error) and "401" (No records found) are problems, and that the 
message should be displayed.  Your mileage may vary.

HTH,

Jonathan
-- 
Jonathan Schwartz
Exit 445 Group
jonathan at exit445.com
http://www.exit445.com
415-381-1852
FileMaker 8 Certified Developer


More information about the FX.php_List mailing list