I have this music site where i have a search sidebar where i want people to be able to find the right musician profile from my table. The search form is built with checkboxes and hooked up to my table with PHP and MySQL. I want people to find profiles from categories like location, user type, genre of music they play and if they have an album release.
<form action="udforsk.php" method="post" enctype="multipart/form-data">
<h2>User type</h2>
<input type="checkbox" name="type[]" value="Solo">
<input type="checkbox" name="type[]" value="Duo">
<input type="checkbox" name="type[]" value="Band">
<h2>Location</h2>
<input type="checkbox" name="location[]" value="area_1">
<input type="checkbox" name="location[]" value="area_2">
<input type="checkbox" name="location[]" value="area_3">
<input type="checkbox" name="location[]" value="area_4">
<input type="checkbox" name="location[]" value="area_5">
<h2>Genre</h2>
<input type="checkbox" name="genre[]" value="genre_1">
<input type="checkbox" name="genre[]" value="genre_2">
<input type="checkbox" name="genre[]" value="genre_3">
<input type="checkbox" name="genre[]" value="genre_4">
<input type="checkbox" name="genre[]" value="genre_5">
<h2>Album or demo</h2>
<input type="checkbox" name="release[]" value="album">
<input type="checkbox" name="release[]" value="demo">
</form>
I want this to be hooked up width a query, but i have problems how to deal with searches where some of the categories haven't been filled out. Like if none of the locations checkboxes is checked all locations is fair game in the query search.
Right now i'm trying to use IN to search after users my query looks like this but it gives me trouble when the $_POST input is empty. Right now i'm just trying to make it work with locations and genre.
$sql = "SELECT artist.ArtistID, artist.ArtistName, artist.RegionID,
artist_genre.ArtistID, artist_genre.GenreID
FROM artist, artist_genre
WHERE artist.RegionID IN ($areaer) AND artist_genre.GenreID IN ($genrer)";
All help how query searches with multiple search variables with checkboxes in general would be alot of help.