I am creating a search engine with AJAX and a prepared statement. The search variables are sent and the AJAX query is successful, but the problem lies with my search query syntax. No matter how exact my search term is to my keywords, my num_rows is always 0. I am adding % %
to search terms, I have tried deleting white space but I am out of ideas.
Examples of keywords are sad, acoustic, electric, blues etc.
<?php
include 'config.php';
$partialSearch = "%".$_POST['partialSearch']."%";
$stmt = $mysqli->prepare("SELECT Name FROM videos WHERE Keywords LIKE ? ");
$stmt->bind_param('s',$partialSearch);
$stmt->execute();
$stmt->bind_result($Name);
if($stmt->num_rows() == 0)
{
echo "No results found for ".$_POST['partialSearch'];
}else{
echo "Results for ".$_POST['partialSearch'];
echo $Name;
}
?>