I recently bought "PHP and MySQL Web Development" by Luke Welling and Laura Thomson. A part of it describes how to create your own custom error handler so that your visitors are presented with something a bit more pleasant then a general PHP error. I have done this and the code extract below shows a customer error handling function. Below the function is the function which lets PHP know what to run when an error is found (in this case the "error_handler" function at the top).
The problem is that the set_error_handler("error_handler"); bit seems to result in an error. Without it, the page is shown and generated without a problem, with it, the error_handler function is run and the following error is shown: Line 19 of c:\Program Files\Apache Group\Apache\htdocs\epigamer\inc\fns_errors.php.PHP Code:<?php
function error_handler ($errno, $errstr) {
echo("<html>
<head>
<title>Sorry, there was an error</title>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<link rel='stylesheet' href='style.CSS' type='text/css'>
</head>
<body bgcolor='#E3E3E3' text='#000000'>
<p>There was an error while generating the page. This is <i>probably</i> not your
fault,<br>and just to make sure, try clicking refresh. The webmaster has been emailed<br>
about this error.</p>
<p><b>Error:<br>
<textarea name='error' cols='65' rows='5'>Line ".__LINE__." of ".__FILE__.".
Error was: $errstr</textarea>
</b></p>
</body>
</html>");
//mail the webmaster
// mail( $settings["webmasteremail"], "epiGamer Error", "There was an error on the epiGamer Site. Error information below.
//
//Line ".__LINE__." of ".__FILE__.".
//
//Error was: $errstr");
//end program
exit;
}
//activate the custom error handling
set_error_handler("error_handler");
?>
Error was: Use of undefined constant content - assumed 'content'.
This confuses me somewhat since I haven't defined any constants anywhere, and the only ones used are LINE and FILE which are both passed from PHP when an error is created anyway.
Does anyone have any ideas where this CONTENT variable is coming from? My database is called "content" but I don't see how that could be related, as this script preceeds the connection to the database.
Thanks as always.




you always need to quote associative array keys.



Bookmarks