Search Not Working - ( Check This Out )

I’ve just made a startling discovery involving the search function on my site. When I type a word in the search field and click “search” it doesn’t return anything instead it takes me to the front page of the site. I’ve gone to wits end and can’t figure out why. Can someone look at this code and tell me what is missing or preventing the search from working? :(Below are the code for the search.

The Form


	<form id="searchForm" action="/search/" method="get">
	<input id="query" type="text" autocomplete="off" placeholder="Search the site" name="query">
	<div id="instantResults" style="display: none;"></div>
			<button type="submit"><span>Search</span></button>
		</form>

The PHP Call Bit

<?php
	
	if ( $_POST )
	{
		$qstr = "" ;
		if ( intval ( $_POST["CatId"] ) > 0 )
			$qstr .= "cat:".intval ( $_POST["CatId"] )."|" ;
		
		if ( $_POST["Keyword"] != "" )
			$qstr .= "q:".str_replace ( "|" , "", $_POST["Keyword"] )."|" ;
		if ( floatval ( $_POST["minPrice"] ) > 0 )
			$qstr .= "p1:".str_replace ( "|" , "", floatval ( $_POST["minPrice"] ) )."|" ;
		if ( floatval ( $_POST["maxPrice"] ) > floatval ( $_POST["minPrice"] ) )
			$qstr .= "p2:".str_replace ( "|" , "", floatval ( $_POST["maxPrice"] ) )."|" ;
		$qstr .= "p:0|gal:0|typ:|" ;
		
		if ( ! empty ( $_POST["sortBy"] ) )
		{
			switch ( $_POST["sortBy"] )
			{
				case "dasc" :
				case "ddesc" :
				case "plow" :
				case "phi" :
					$qstr .= "ord:".$_POST["sortBy"] ;
					break;
				default:
					$qstr .= "ord:ddesc" ;
					break;
			}
		}

	}
	
	header ( "location:".base_url."c-BrowseClassified/$qstr/" ) ;
	exit ( ) ;


?>

The Search PHP Template


<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<?php include ( "core/inc.meta.php" ) ?>
</head>
<body id="home">
	<?php include ( "inc.header.php" ) ?>
	<!-- end: #header -->
	<div id="shell">
		<?php include ( "inc.search_header.php" ) ?>
		<!-- end: #search -->
		<div id="content">
			<div id="major">
				<div class="panel">
					<div class="inner">
						<h1><em><?php echo $qstring[1] ?></em> Search Results</h1>
						<p>Select a site below to see its current items:</p>
						<ul id="storeCollection">
						
						<?php
							if ( ! empty ( $websites ) )
							foreach ( $websites as $website ) :
							
						?>
						
							<li>
								<a class="thumb" href="<?php echo base_url.get_sef_url ( $website["WebsiteID"] , "Website" ) ?>/" title="<?php echo $website["WebsiteTitle"] ?> Website Items">
									<img src="<?php echo base_url."media/".$website["WebsiteID"].".jpg" ?>" alt="<?php echo $website["WebsiteName"] ?>">
									<br>
									<?php echo $website["WebsiteName"] ?></a>
							</li>
						<?php
							endforeach ;
							else
							{
						?>
							<li>
								<h2>No result found for <em><?php echo $qstring[1] ?></em></h2>
							</li>
						<?php
							}
						?>
						</ul>
						<div class="break">
						</div>
					</div>
				</div>
			</div>
			<!-- end: #major -->
			<div id="minor">
				
				<?php
					include ( "inc.social.php" ) ;
				?>
				
				<div class="panel">
					<div class="inner">
						
						<div class="break">
						</div>
						<div class="tagCloud">
							
							
						<?php
							$g_ads = $data->select ( "MarketingAdManager" ,"*", array ( "MarketingPlacing" => "Home Side Bar" ) ) ;
							if ( ! empty ( $g_ads ) )
								foreach ( $g_ads as $g_ad )
									echo $g_ad["MarketingScript"]."<br><br>" ;
						?>
							
							
						</div>
						
					</div>
				</div>
				
			</div>
			<!-- end: #minor -->
			<div class="break">
			</div>
		</div>
		<!-- end: #content -->
	</div>
	
	
	<div align="center" style="clear:both">
		<?php
			$g_ads = $data->select ( "MarketingAdManager" ,"*", array ( "MarketingPlacing" => "Home Bottom" ) ) ;
			if ( ! empty ( $g_ads ) )
				foreach ( $g_ads as $g_ad )
					echo $g_ad["MarketingScript"]."<br><br>" ;
		?>
	</div>
	
	
	<?php include ( "inc.footer.php" ) ?>
	<!-- end: #footer -->
</body>
</html>

From what I see, clicking on the Search will take you to search folder in the ROOT directory. In that folder there maybe an index file or .htaccess file that redirects you to your front page.

Hi Tom, in the root there are both an index and .htaccess file. The .htaccess file has the lines below


Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^admin$ Admin/index.php?qstr=$1 [L]
RewriteRule ^(.*)/$ index.php?qstr=$1 [L]

There are also the following files:

1. search.php
2. search_query.php
3. search_result.php

Forgive my noobishness but how can I get clicking “Search” to display the search result instead of redirecting to the front page?

Is this part of a CMS? This could be a red herring, but I’ve seen this happen on one CMS when there there was a temporary index.html page in the root folder.

Hi Ralph, yup this is part of the same CMS I’ve been coming here for. I do see index.html files in several folders of the CMS package. The content of the index.html looks like this


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Access Denied</title>
</head>

<body>
<div style="padding:8px; margin:11px; font-family:Arial, Helvetica, sans-serif; font-size:12px; background-color:#F3F3F8">
Directory Access denied
</div>
</body>
</html>


I was just wondering if there’s one in the root folder of the site (that is, the main site folder that everything else is in). What CMS is it?

On your form, update this line:

<form id=“searchForm” action=“/search/” method=“get”>

to this:

<form id=“searchForm” action=“/search.php” method=“get”>

Let us know the result.

I don’t see one in the main folder or root. Only folders like images, admin, etc has one. As for the CMS it’s a custom deals cms.

I changed that but I’m still getting the same result. Looking at the address bar on my browser it shows h ttp://www.mysite.com/base_urlc-BrowseClassified/

I’m wondering if this bit of code has anything to do with it:

    header ( "location:".base_url."c-BrowseClassified/$qstr/" ) ;
    exit ( ) ;

It could be. Lets find out what it is. Just place this on top of the header:

echo “location:”.base_url.“c-BrowseClassified/$qstr/”;

Note that you will get an error message also.

It didn’t show an error rather the browser window printed exactly: location:base_urlc-BrowseClassified//

Ok so I was missing this bit of line

	&lt;form id="searchForm" method="post" action="&lt;?php echo base_url ?&gt;search_query/"&gt;

Problem solved.