ericp Posted June 27, 2014 Share Posted June 27, 2014 Hi everyone, As my header.html included file needs to connect to the dadabase for retrieving data, I have to include the config.inc.php script (18.3) in it, but not the individual file, e.g., register.php, etc, as per the chapter 18 outlines. You know, the errors directly display on the web browser instead of being sent to the defined email. Do you know why? And how can I get it sent to as per the my_error_handler function triggers? Note: In my .ini file, I changed the error_reporting to E_ALL, and log_errors to on , and I am not sure if these changes caused the problem or not? Can you help? Thanks Link to comment Share on other sites More sharing options...
Larry Posted June 27, 2014 Share Posted June 27, 2014 It'd probably help to see some code. And have you confirmed that your error handler is being called, not the default PHP error handler? Link to comment Share on other sites More sharing options...
ericp Posted June 28, 2014 Author Share Posted June 28, 2014 I have made no change to the codes. As my header.html has two languages, I have to include the config.inc.php because the config.inc.php file defines the location of the MySQL connection script, mysqli_connect.php. Without this step, my header.html cannot function and cannot print the languages repectively, either. The difference between yours and mine is that you include the config.inc.php in the individual .php files along with the code of 'require (MYSQL); ' when you make the query for the tasks; whereas I include them in the header file only. The similarity between yours and mine is that we both use the error trigger ( 'or trigger_error("Query: $q\n<br />MySQL Error: " .mysqli_error($dbc)); ') right in the $result=....; In my opinion, if we include the config.inc.php, the error handler should(must) be called because it has been really really included in it. Everything goes smoothly for me. However, the question in my head is that why does it not send the errors, if any as i test the writing scripts, to my defined email, but print it on the browser as if the error_handler function in the config.inc.php file was ignored. Does it technically ignore the error_handler function if it's not included directly in the writing file, to your coding experience? or what? I am confused/concerned about whether php programming language itself ignores the function that is included in the 'included' file? Link to comment Share on other sites More sharing options...
Larry Posted July 7, 2014 Share Posted July 7, 2014 I'm just guessing without seeing code, but perhaps this is a live/test mode issue? Because the error handler behaves differently based upon that setting (I believe). It's also not clear if you know whether the error handler is being called or not (because it behaves differently than PHP's default error handler, so it should be obvious). But... If you have a function defined in an included file, that function becomes available to a script as soon as that file is included. In other words, includes behave exactly as if that code was inserted into the including script at that point. Link to comment Share on other sites More sharing options...
ericp Posted August 30, 2014 Author Share Posted August 30, 2014 Sorry for late response, but I was really busy in the last few weeks. Ok. To be short, let me briefly show you the codes of my pages as follows: 1/ Index.php page: <?php Include the header include ('includes/header.html'); //codes to show/echo the page content <p> bla bla </p> //Include footer include ('includes/footerl.html'); ?> 2/ The header.html file: <?php //start a session session_start(); // Include the configuration file: require ('includes/config.inc.php'); // Get the words for this language: require (MYSQL); //include lang choice require ('includes/languages.inc.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo $page_title; ?> </title> </head> <body> <p> neccessary items for header part. </p> 3/ footer.html file </body> </html> <?php // Flush the buffered output. ob_end_flush(); ?> In the header.html file, you can see that I included the config.inc.php, which is the copied one of yours, and the languages.inc.php, which stores and retrieves the language ID as your script 17.1.php does. This languages.inc.php does not need the database connection because the database connection had been included in the config.inc.php (define ('MYSQL', './database/mysqli_connect.php');, which goes before this file in the header.html In my every query to SELECT, INSERT INTO, DELETE, ect in the main pages such as register.php, view_posts.php, ect, I include the the error trigger ( 'or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); ') right in the $result=....; And I try testing by purposedly adding error into the code so that it would send to my assigned email address, but it didn't. The error returned directly in browser. Can you help? Thanks a lot! Link to comment Share on other sites More sharing options...
Larry Posted September 2, 2014 Share Posted September 2, 2014 Nope, the configuration file DOES NOT include the MySQL configuration file (I don't believe). The configuration file defines where the database configuration file IS, but doesn't include it. Subsequent pages then use the constant defined in the configuration file to include the MySQL configuration script. Link to comment Share on other sites More sharing options...
ericp Posted September 5, 2014 Author Share Posted September 5, 2014 Perhaps, my English is not sufficient enough to explain the file system that I organized, or I chose the wrong word to explain it. Yes, you are right, and I also beleived so. So, according to my file organization, do you have any idea about how to trigger/call the my_error_handler( ) function to handle the errors, which is established in the configuration script? For example, how can we call it in the index.php page (view all posts created and posted by all users of the forum) in case that we have any error in the query ($q ="SELECT ...";) within the page's content section, while the configuration file has already been in the header section? Sorry if my explanation is still vague to you. Link to comment Share on other sites More sharing options...
Larry Posted September 11, 2014 Share Posted September 11, 2014 The use of the custom my_error_handler() has nothing to do with the file structure. If you've defined the error handler in the configuration file, and told PHP to use it, then any non-parse error in any script will use your error handler (if the script has already included the configuration file). Maybe you should share some applicable code here? Link to comment Share on other sites More sharing options...
Recommended Posts