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); Link to comment https://forums.phpfreaks.com/topic/134248-solved-query-or-die-redirect-page/ 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 Link to comment https://forums.phpfreaks.com/topic/134248-solved-query-or-die-redirect-page/#findComment-698845 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">'); Link to comment https://forums.phpfreaks.com/topic/134248-solved-query-or-die-redirect-page/#findComment-698848 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"); } Link to comment https://forums.phpfreaks.com/topic/134248-solved-query-or-die-redirect-page/#findComment-698852 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. Link to comment https://forums.phpfreaks.com/topic/134248-solved-query-or-die-redirect-page/#findComment-698861 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. Link to comment https://forums.phpfreaks.com/topic/134248-solved-query-or-die-redirect-page/#findComment-698880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.