Jump to content

Archived

This topic is now archived and is closed to further replies.

walleyspunk

Page Redirect

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.

Share this post


Link to post
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]


Share this post


Link to post
Share on other sites

×

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.