Hello this my first time on Stack Overflow and i am a begginer in php and phpMyAdmin. I have an error that i can’t understand.
I have a search bar with a redirect button. I can succesfully search a product by writing "cere" (cereal in my database).
Clicking the button will give me every details i have for the product cereal.
This code below is my code at the moment.
function SearchProducts(PDO $db, string $research): array
{
$datas = array(
'research' => '%' . $research . '%'
);
$sql = "SELECT * FROM product WHERE name LIKE :research WHERE description LIKE :research";
$qry = $db->prepare($sql);
$qry->execute($datas);
$products = $qry->fetchAll();
return $products;
}
My problem is, i want to be able to search the product "cereal" with its description also that i have in my database.
It gives me an error saying that my "WHERE description LIKE" is wrong. Can someone help me?
>Solution :
Its kind of difficult to know if you have other errors, since you didn’t post your html, but the error your getting is only because you have a seconde WHERE. If you want to be able to search a product with its description, you can use OR instead of the second WHERE.
Hope it helps.
$sql = "SELECT * FROM product WHERE name LIKE :research OR description LIKE :research";
$qry = $db->prepare($sql);