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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.