Redirecting On Error PHP Help

You now have a complex mechanism in place to deal with error messages as they crop up, and you even have a way of printing out errors for your programming edification (with debug_print). Now, it’s time to see how to use the error information. Take a look at one of your simplest page/script combinations: connection.html and connect_php.

Update connect.php to show_user.php

Right now, correct.one just uses die to report problems in connecting to your database:
Update connect.php to show_user.phpRight now, if my sql_ connect fails, the entire script just goes down in a ball of flames. Not so great. One way you could fix the problem would be to do something like this:

Update connect.php to show_user.php

This example uses your new error page in conjunction with PHP’s redirect. In addition, it supplies both a friendly and system-level error, so it should work pretty well. For the sake of testing, type in a bad database host. like this one:

Update connect.php to show_user.php

Next, go to Connect.html in your browser, submit the form to connection.php and you should be rewarded with your error page, as in Figure 8-12. In terms of seeing errors, you have your users-and yourself-covered.

FIGURE 8-12

FIGURE 8-12

Now, set DEBUG_MODE to false in app.config.php:

// Set up debug mode
define(DEBUG_MODE”, false);

Try going to connect.tum! and connect.php again; this time, you should only see the user-facing error (check out Figure 8-13) .

FIGURE 8-13

FIGURE 8-13

Posted on January 11, 2016 in When Things Go Wrong (and They Will)

Share the Story

Back to Top
Share This