Jump to content

Search


anevins

Recommended Posts

Hi there,

I'm working on a search bar for my website and I want what ever someone types in, to be like the data in my table column name.

 

My table column name is 'make',

my table name is 'stick'.

 

At the moment, my code outputs " your search: "..mysearchterm.." returned zero results", even when i type in the same name as a row in my column.

 

Can anyone make sense of why my code's not performing?

 

<form id="search" name="search" id="search" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" />
<input type="text" name="terms" value="Search..." />
<input class="button" type="submit" name="Search" value="Search" />
</form>
<?php 
include_once('connectvars.php');

if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) {

$terms = $_GET['terms'];
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die *('Error connecting to MySQL server');
// Query the database.
$query = "SELECT sid, type, colour, make FROM stick WHERE make LIKE '%$terms% '";
// Fetch the results.
$result=mysqli_query($dbc,$query);	
// Print the results:
$num_rows = mysqli_num_rows($result);

// If the results of the query match to 1 or more rows, display the products by their title, price and image.
	if ($num_rows > 0){ 
			if($result=mysqli_query($dbc,$query)){
					$output = Array();
					while($row=mysqli_fetch_assoc($result)) {
//'<br /> Street: ' .$row['street'].'
					$output[] = '<ul>';
					$output[] = '<li> Type: '.$row['make'] .' Size: '.$row['type'].'<br />Colour: '.$row['colour'] . '" /></li>';
					$output[] = '</ul>';
					}
				}
		echo join('',$output);
	}

// If the results don't match the titles of the table, output this message.
	else {
		echo "<h3>Sorry,</h3>";
		echo "<p>your search: "" .$terms. "" returned zero results</p>";
	}

} 

else { // Tell them to use the search form.
echo '<p class="error">Please use the search form at the top of the window to search this site.</p>';
}	

?>

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/230540-search/
Share on other sites

Archived

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

×
×
  • Create New...

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.