Jump to content

Page Redirect


walleyspunk

Recommended Posts

I'm trying to redirect back to a search page when my query doesn't come up any results. If I use
header("Location: search.php"); I get the following error since the page has already sent page info:
Warning: Cannot modify header information - headers already sent...

Is there any 'other' way to redirect a page that makes sense for what I'm doing???


[code]
    
$recordcount = mysql_query($_SESSION["SQL_STR_PAGE"]) or die("Couldn't query " . mysql_error());

$total = mysql_result($recordcount, 0, 0);
    
global $msg_noresults;

    if( $total == 0 ){
        $msg_noresults = "Your search returned no results. Please try again.";
        header("Location: search.php");
        exit();
    }

[/code]

Additional info: I run the query. If my query returns a hit count of 0, I want to go back to my search page and let the user try another search. The test occurs half way down my page, so header info is already sent.

Link to comment
Share on other sites

OK, maybe I've answered my own question. I used the following meta refresh tag in and it works, but now i can't get my $msg_noresults to print out on the search.php page.

If i make $msg_noresults a global, will it remain in scope with the new page comes up? Or, do I have to save it in a session variable?

Not sure if a global variable will maintain its value across page/file changes? can anyone explain?


[code]

if( $total == 0 ){
        $msg_noresults = "Your search returned no results. Please try again.";
        echo '<meta http-equiv="refresh" content="0; URL=http://www.url.com/search.php">';
    }

[/code]


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.