byxgm3rx Posted February 12, 2021 Share Posted February 12, 2021 Hey guys for a project im making a search filter function. Only one filter seems to be working and that's the genre filter :( This is my code: function filterFilms(){ global $conn; $loop = 0; if(isset($_POST['titel']) && !empty($_POST['titel'])){ $titel = sanatize($_POST['titel']); } if(isset($_POST['genre']) && !empty($_POST['genre'])){ $genre = sanatize($_POST['genre']); } $sql = "SELECT TOP 20 * From Movie Inner Join Movie_Director On Movie_Director.movie_id = Movie.movie_id Inner Join Movie_Genre On Movie_Genre.movie_id = Movie.movie_id Inner Join Person On Movie_Director.person_id = Person.person_id"; if(isset($titel) && !empty($titel)){ if($loop == 0){ $sql .= " WHERE ( title = ':titel' OR title like ':titel')"; $loop++; } else{ $sql .= " AND ( title = ':titel' OR title like ':titel')"; } } if(isset($genre) && !empty($genre)){ if($loop == 0){ $sql .= " WHERE genre_name = :genre"; $loop++; } else{ $sql .= " AND genre_name = :genre"; } } $query = $conn->prepare($sql); if(isset($titel) && !empty($titel)){ $query->bindValue('titel', $titel,PDO::PARAM_STR); } if(isset($genre) && !empty($genre)){ $query->bindParam('genre', $genre,PDO::PARAM_STR); } $query->execute(); $rows = $query->fetchAll(); return $rows; } Anyone any idea?? Quote Link to comment https://forums.phpfreaks.com/topic/312139-search-filter-function-not-working/ Share on other sites More sharing options...
Barand Posted February 12, 2021 Share Posted February 12, 2021 18 minutes ago, byxgm3rx said: WHERE ( title = ':titel' OR title like ':titel')"; Don't put quotes around placeholders And "LIKE" without widcards is a wast of time Quote Link to comment https://forums.phpfreaks.com/topic/312139-search-filter-function-not-working/#findComment-1584429 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.