handling error codes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

handling error codes

Post by chris_s_22 »

when been doing the coding i notice that when ive tested each function to make sure everything working that when a error is displayed it goes to a blank page and displays it, what i want is one page that i can customise and disaplays the error on that page, here are all my errors

Code: Select all

 
else
    { echo "Wrong Confirmation code";}  
 

Code: Select all

 
die ('Could not connect to the database.');
 
can i replace the above errors with the following code without a problem?

Code: Select all

 
// show error page with the error
          $reg_error = description of the error here';
          include 'error.php';
          exit;
 
then on the error page have something like

Code: Select all

 
<?php if (isset($login_error)) { ?>
There was an error: <?php echo $login_error; ?>, please try again.
<?php } ?>
 
is there any reason why this wouldnt work or is there a simpler way
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: handling error codes

Post by it2051229 »

so you want to create a page where you can create your own error messages and that page gets called whenever something goes wrong. yes it is possible.. remember code 404? the page not found? you could also do the same, you create codes(e.g. 404) and you pass that code to the page of error messages and then the page returns the appropriate message.
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: handling error codes

Post by desperado »

your code should work, or you can try this:

Code: Select all

 
 
if (blah) {
echo "yay";
}else{
          $error = description of the error here';
          echo "<script>";
          echo "location.replace('error.php?errorID=$error');";
</script>
          exit;
 
then on the error page:

Code: Select all

 
<?php 
if (isset($_GET['errorID'])) {
$error = $_GET['recordID'];
echo "There was an error: $error, please try again.";
?>
 
Post Reply