phpinfo() Posted November 25, 2008 Share Posted November 25, 2008 I have a function that dies and gives a message if there is a MySQL error: $result=mysql_query($query,$id) or die ("Unable to execute query \"".$query."\": ".mysql_error()); Is there a way to have it die and redirect to an error page instead of just giving an error message? I tried the below code, but I kept getting a too many redirects error from my browser: $error_page = header('error.php'); exit(0); $result=mysql_query($query,$id) or die ($error_page); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 25, 2008 Share Posted November 25, 2008 Did you try: <?php $result=mysql_query($query,$id) or header('error.php'); ?> You might want to store the error in a session variable that can be picked up on the header page: <?php session_start(); $result=mysql_query($query,$id); if (!$result) { $_SESSION['db_error'] = mysql_error(); $_SESSION['db_query'] = $query; header('error.php'); exit(); ?> Ken Quote Link to comment Share on other sites More sharing options...
bluesoul Posted November 25, 2008 Share Posted November 25, 2008 $result=mysql_query($query,$id) or die ('<META HTTP-EQUIV="Refresh" CONTENT="0;URL=error.php">'); Quote Link to comment Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 Or yet another idea to try $result=mysql_query($query,$id); IF (!$result){ header ("location: error.php"); } Quote Link to comment Share on other sites More sharing options...
phpinfo() Posted November 25, 2008 Author Share Posted November 25, 2008 $result=mysql_query($query,$id) or die ('<META HTTP-EQUIV="Refresh" CONTENT="0;URL=error.php">'); Thanks, the meta redirect works perfect. Quote Link to comment Share on other sites More sharing options...
bluesoul Posted November 25, 2008 Share Posted November 25, 2008 Good to know since I didn't actually test that code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.