techpro Posted June 27, 2007 Share Posted June 27, 2007 I'm running a PHP/MySQL script on my server. Sometimes, presumably due to some transient problem with the MySQL server, the script displays warnings like: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/blah_blah/file.php on line xx on the page. It's not a script error, because the same page can display perfectly a couple of minutes later. I wanted to have the script display a friendly page saying there is a temporary error, please come back later, when this occurs. With the help of this article I have learned how to trap PHP errors and display my own output. But the output still appears after whatever HTML has already been generated by the script. Is there a way to get the browser to clear everything that has been output so my error message always starts on a clean page? Rewriting the script so that nothing is printed until the end would be way too complicated. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/57391-clear-output-to-show-error-page/ Share on other sites More sharing options...
.Stealth Posted June 27, 2007 Share Posted June 27, 2007 I usually gather all of the errors on my page using an array. <?php $errors = array(); if($something){ $errors[] = "An error has occured, unable to fetch info from the database"; } if(empty($errors)){ //do the right thing }else{ //display error page } ?> Link to comment https://forums.phpfreaks.com/topic/57391-clear-output-to-show-error-page/#findComment-283921 Share on other sites More sharing options...
techpro Posted June 27, 2007 Author Share Posted June 27, 2007 Thanks. I didn't write the script. I'm trying to find a solution that requires minimum modification to the existing code, preferably just adding an include line at the top for the error handler. So I can't do anything about what's been output to the browser by the time an error occurs. Link to comment https://forums.phpfreaks.com/topic/57391-clear-output-to-show-error-page/#findComment-283946 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.