<?php
$searchErr="";
function test_input($data) {
$data = trim($data); //whitespacess
$data = stripslashes($data); //removes backslashes n clean data from database or form
$data = htmlspecialchars($data); //converts predefined characters to html entities, encoding user input so that they cannot manipulate html codes
return $data;
}
if ($_SERVER["REQUEST_METHOD"]=="POST")
{
if(isset($_POST["searchQuery"]))
{
if(empty($_POST["searchQuery"]))
{
$searchErr="Field cannot be empty!";
}
else //no error
{
$searchData=test_input($_POST["searchQuery"]);
$searchData=preg_replace("#[^0-9a-z]#i","",$searchData);
echo $searchData;
require_once('includes/db_connect.php');
$sQuery ="SELECT * FROM food WHERE Food_Name LIKE BINARY :searchData OR Food_Description LIKE BINARY :searchData";
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt=$conn->prepare($sQuery);
$stmt->bindParam(':searchData',$searchData); //binding var to parameter
$stmt->execute(); //executing prepared statement and returning
result to obj $numResults=$stmt->rowCount();
if($numResults==0)
{
$msg="Your search did not match any of our available
foods!";
echo $msg;
}
else
{
while($row=$addResult->fetch(PDO::FETCH_ASSOC))
{
echo $row['Food_Name'];
echo "<br/>";
}
}
}
}
}
?>
<?php
I am currently working on a website. In a section, I have a search bar which i use to search for text- match from my database. However, when I am getting the results, only texts which are case-sensitive are being returned. Please can u help me? I am using Apache and phpMyAdmin