Hi, I have a quick question about using the PHP die() function. I'm building a site around a MySQL database, and when I connect to the database from a PHP page I use the following code:
$connection = mysql_connect($host, $user, $password) or die("Error connecting to SQL server"); $db = mysql_select_db($database, $connection) or die("'Error connecting to database"); Simple enough so far right? So if there is a problem connecting in anyway, an error message appears. What I want though is to redirect to a properly separate error page, rather than just have a basic text mesage. I changed the code to this: $connection = mysql_connect($host, $user, $password) or die("Error connecting to SQL server"); $db = mysql_select_db($database, $connection) or header('Location: ../errors/databaseselect.php'); Which works fine (tested by deliberately misnaming database so it can't find it). However if I then use the same approach for the server connection error, like below, it doesn't work. $connection = mysql_connect($host, $user, $password) or header('Location: ../errors/servererror.php'); $db = mysql_select_db($database, $connection) or header('Location: ../errors/databaseselect.php'); I get a variety of error messages dependant on what I tweek to try and make it work. I've tried all I can think of, and I've tried putting the header function inside a die function to no avail. I don't understand why it works for the database connect error but not the server error. If anyone has any suggestions as to what the problem is or how I could improve my technique I'd love to know. I'm sure I can't be the only person who has wanted to do something like this, but I can't find any references online to anything other than simple text error messages. I'm relatively new to PHP but not programming in general so please don't be afraid to fire big words at me. Thanks in advance! John G -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php