I'm working on a simple search engine that gets you information but I'm having a problem. You see when I put a space into the search input it doesn't give you the message saying "no key words searched please try again" but when you click the search button without adding anything in the search input it works. How could i fix this to make it work with both?
Code:
if(!$db) {
die('sorry we are having some problbems');
}
$searchTerm = mysqli_real_escape_string($db,$_GET['term']);
if ( empty($searchTerm))
{
echo("no key words searched please try again");
}
else
{
$sql = mysqli_query(
$db,
sprintf(
"SELECT * FROM searchengine WHERE name LIKE '%s' LIMIT 0,20",
'%'. $searchTerm .'%'
)
);
while($ser = mysqli_fetch_array($sql)) {
echo "<a href='$ser[pageurl]'>$ser[img]</a>";
}
}
mysqli_close($db);
?>