Jump to content

handling error codes


chris_s_22

Recommended Posts

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

 

else
{ echo "Wrong Confirmation code";}  

 

die ('Could not connect to the database.');

 

can i replace the above errors with the following code without a problem?

 

// 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

<?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

Link to comment
https://forums.phpfreaks.com/topic/140218-handling-error-codes/
Share on other sites

You could create a generic error page and when you come across an error, use a function like this:

 

<?php
function error($msg) {
    header('Location: error.php?msg=' . $msg);
    exit;
}
?>

 

And then your error page would be a simple page that just displays the error message from the GET variable:

<?php if (isset($_GET['msg'])): ?>
There was an error: <?php echo $_GET['msg']; ?>, please try again.
<?php endif; ?>

 

So when you come across an error:

<?php
else { 
    error("Wrong Confirmation code");
}  
?>

Link to comment
https://forums.phpfreaks.com/topic/140218-handling-error-codes/#findComment-733695
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.