I am trying to make a small search function to look at database using this code:
$searchQ = 'Li';
$query = $connDB->prepare('SELECT * FROM topic WHERE topic_name LIKE '."':keywords'");
$query->bindValue('keywords', '%' . $searchQ . '%');
$query->execute();
if (!$query->rowCount() == 0) {
while ($results = $query->fetch()) {
echo $results['topic_name'] . "<br />\n";
}
} else {
echo 'Nothing found';
}
This return all of the items in database, not just the ones that are alike,
I then ran this SQL query:
SELECT * FROM topic WHERE topic_name LIKE '%Li%';
and this ran as expected and returned the required result.
What am I missing?