currently working on a search form and it’s going great, however it’s not picking up any of the results successfully.
Here’s a screenshot of the database
http://screensnapr.com/e/IdNs9j.png
As you can see there are several results with the word “dragon”
Now if you go to search.php?name=dragon it brings up these results:
Results
Sorry, your search: dragon returned zero results
You searched for: dragon
Results
End of results
Here’s the search query:
$searchTerm = trim($_GET['search']);
$query = "select * from item where name like '$searchTerm' order by name";
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
if ($numrows == 0) {
echo "<h4>Results</h4>";
echo "<p>Sorry, your search: " . $searchTerm . " returned zero results</p>";
}
Why is it not displaying any of the results? Any help would be appreciated.
YOu didn’t specify the wildcard operators for the
likeoperation. Without wildcards,somefield LIKE 'something'is exactly the same assomefield='something'.Your query should be
and note that you’re WIDE open to SQL injection attacks. At bare minimum you should have
or better yet, switch to using PDO prepared statements.