Jump to content


Photo

Page Redirect


  • Please log in to reply
1 reply to this topic

#1 walleyspunk

walleyspunk
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 11 April 2006 - 09:28 PM

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


    
$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();
    }


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.



#2 walleyspunk

walleyspunk
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 11 April 2006 - 09:44 PM

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?



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">';
    }








0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users