Hi Guys,
Trying to build a search facility:
http://www.slougheaz.org/greenock/search/search.php
But have a problem with it.
Problem: When I hit submit without entering any data or hit submit after entering any specific term like dog or cat or anything it returns all the results in the database. So basically all it's doing nomatter what you enter as the searcg criteria it returns all results in my DB.
Can anyone please advise – here’s the search code:
<?php
// Connect to DB;
include("***************");
// Define Variable form 'Query' post;
$q = isset($_GET['query']) ? trim(stripslashes(htmlspecialchars($_GET['query']))) : NULL;
// Use like to match with the % wildcards;
$query=mysql_query("select * from ******* where opening like '%$query%' or body_text like '%$query%'") or die(mysql_error());
while($rows = mysql_fetch_assoc($query)) {
echo '<a href="http://www.slougheaz.org/test.php?newsid='. $rows['story_id'] .'">'. $rows['headline'] .'</a><br>';
echo $rows['opening'].'<br><br>';
}
// If no record!!;
$no_records = "Sorry - no Record Found";
if (mysql_num_rows($query) <= 0) {
print ("$no_records");
}
?>