Jump to content

Custom MYSQL error pages


holowugz

Recommended Posts

Most assuredly yes. Now the question is how exactly your page is formatted as to how to proceed. If no output has yet been generated you can use header("Location: {url}"). If this method will not work for you I could make other suggestions such as embedded errors or other methods of redirection, but for now we will just use header().

[code]<?

$conn = mysql_connect('localhost', 'username', 'password') or header("Location: mysql_error.php?err=".urlencode(mysql_error()));

?>[/code]

This attempts a connection to the server and if an error is encountered it redirects to a page to display the error.

On the mysql_error.php page you need to decode the error and display it how ever you like. I'm not sure exactly what you want to do with it so I really can't be too specific here.

[code]<?

$mysql_error = urldecode($_GET['err']);

?>[/code]

This may not be the method you want to use, but I hope I have at least pointed you in the correct direction.
Well the embedded error will depend greatly on the way you layout your code. You could simply do a [b]or die("formatted error result");[/b] at the end of your mysql commands.

There are a couple of ways of doing this and getting the results you want, but it all depends on the layout of your code. This is just one basic example, but more then likely it isn't exactly what you are looking for. You could simply create a $header and $footer for the beginning and end of all your error strings to save yourself from typing lots of xhtml.

Additionally, unless the server you intend to use specifically supports PHP5 then you should design based on PHP4. If your server does support PHP5 then you may want to check into thorpe's response.

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.