Jump to content

[SOLVED] Query or die redirect page???


phpinfo()

Recommended Posts

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

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

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.