Php (Meta Refresh) Redirection Problem !!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nita
Forum Commoner
Posts: 39
Joined: Wed May 02, 2007 5:49 am

Php (Meta Refresh) Redirection Problem !!

Post by nita »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi
I'm building little script (movie collection).

The problem is that when:
-there is no results - browser is showing a communicate and redirecting back to the root (index.php) after 2 sec
-input is less then 2 char - browser is showing a communicate and redirecting back to the root (index.php) after 2 sec

to test it go to:
[url]
http://www.nita-on-line.com/movies/
[/url]

code for search part of the application --

Code: Select all

else if(isset($_POST['submit'])||isset($_POST['search'])) // when search button is pressed
{
echo "
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
'http://www.w3.org/TR/html4/loose.dtd'>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<LINK REL='StyleSheet' href='movies.css' TYPE='text/css'>
<title>Nita Movies</title>
</head>
<body>
<table width='950'>
<tr>
	<td bgcolor='#663300' width='180' border='0' cellspacing='0' cellpadding='0'  valign='top' class='font2' >";
	$result = mysql_query("SELECT * FROM category ORDER BY cat") or die(mysql_error());
	while($row = mysql_fetch_array( $result )) 
	{
	
	echo "<A href='index.php?cat=$row[cat]'>$row[cat]</a><br>";
	}
	echo "	
	<br>
	<form method='post' action='$php_self'>
	<input type='text' name='search' size=25 maxlength=25 minleneght=2><br>
	<input type='Submit' name='Submit' value='Submit'>
	</form>
	</td>
	
	<td class='font2'>";

	$PHP_SELF = $_SERVER['PHP_SELF'];

	$search=$_POST["search"];

	$minchar = 2;
	if (strlen($search) < $minchar)
	{
	    echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
				'http://www.w3.org/TR/html4/loose.dtd'>
				<html>
				<head>
				<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
				<META HTTP-EQUIV='REFRESH' CONTENT='2; URL=$PHP_SELF'>
				<LINK REL='StyleSheet' href='movies.css' TYPE='text/css'>
				<title>Nita Movies</title>
				</head>
				<body>";

		echo "Search must be longer than 2 characters.
		</body>
		</html>
";
} 
	else 
	{
	    $result = mysql_query("SELECT * FROM movies WHERE name LIKE '%$search%' 
	    OR cast LIKE '%$search%' OR director LIKE '%$search%' 
	    OR year LIKE '%$search%' OR production LIKE '%$search%'
	    OR genere LIKE '%$search%' OR language LIKE '%$search%'");
	
	    $numrows=mysql_num_rows($result);
	    if ($numrows == 0)
  	    {
  	          echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'
				'http://www.w3.org/TR/html4/loose.dtd'>
				<html>
				<head>
				<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
				<META HTTP-EQUIV='REFRESH' CONTENT='2; URL=$PHP_SELF'>
				<LINK REL='StyleSheet' href='movies.css' TYPE='text/css'>
				<title>Nita Movies</title>
				</head>
				<body>";
			echo "<p>Sorry, your search returned 0 results</p>
			</body>
			</html>
";
			
  	    }
	    else 
	    { 
	        while($row=mysql_fetch_array($result))
	        {	
       	        include "display_rec.php";
	        }
	    }
	}
 	echo "
	</td>
</tr>
</table>
</body>
</html>
";

}
For example when i.m browsing one of the categories and then do search resulting in these communicates. saerch for "a" or "hghjdjjd"
Browser is redirecting me to the root of the application, what i want to be done, is that browser will redirect me to the place i started my search from.

if some one can help me to find a solution for that one.
im happy to publish entire code of the apllication (its not too long) if you think that my help to solve a problem.

Thanks a lot in advance
Nita


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
nita
Forum Commoner
Posts: 39
Joined: Wed May 02, 2007 5:49 am

SOLVED

Post by nita »

all i had to do is replace:

$PHP_SELF = $_SERVER['PHP_SELF'];

with

$PHP_SELF = $_SERVER['HTTP_REFERER'];


hope some of you find it useful.

nita
Post Reply