walleyspunk Posted April 11, 2006 Share Posted April 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7142-page-redirect/ Share on other sites More sharing options...
walleyspunk Posted April 11, 2006 Author Share Posted April 11, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/7142-page-redirect/#findComment-25997 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.