I have a search form to seach for motor parts. The form consists of two text fields one for new parts and one for used:
<form action="/artikelen/zoeken" method="post" name="zoek-form" id="zoek-form">
<input name="nieuw" type="text" placeholder="Onderdelen nieuw">
<input name="gebruikt" type="text" placeholder="Onderdelen gebruikt">
<button type="submit">Zoeken</button>
</form>
I use the following model to query the database:
public function get_zoek_resultaten($term,$status)
{
$sql = "SELECT P.*
, PF.foto
FROM producten P
JOIN product_fotos PF ON P.product_id = PF.product_id
WHERE (product_naam LIKE :term OR product_omschrijving LIKE :term)
AND product_status = :status";
$stmt = $this->pdo->prepare($sql);
$stmt->execute(array(':term' => $term.'%', ':status' => $status));
return $stmt->fetchAll();
}
and I have the following in Controller zoeken
$nieuw = filter_input(INPUT_POST, 'nieuw', FILTER_SANITIZE_STRING);
$gebruikt = filter_input(INPUT_POST, 'gebruikt', FILTER_SANITIZE_STRING);
if ( $nieuw )
{
$conditie = $nieuw;
}
elseif ( $gebruikt )
{
$conditie = $gebruikt;
}
$zoek_resultaten = $this->artikelen->get_zoek_resultaten($conditie,$conditie);
But no matter what I enter in one of the two fields, no records are returned. What is wrong with this approach?
Thank you in advance