I'm trying to make an advanced search page in
JSP where the user can search based on multiple criteria...
But I want the user to be able to leave some of the criteria blank (i.e. under gender, if they went male and female results, then they just don't change the select box)
So I've done something like this, leaving the option value of the first/default selection blank in hopes that it will pass on a blank entry to the next page and when i select * from cases where gender = '', I want it to show all the males and females. BUT this isn't working.
out.print("<p>Gender:");
out.print("<select name=\"gender\">");
out.print("<option value =\"\"></option>");
out.print("<option value=\"Male\">Male</option>");
out.print("<option value=\"Female\">Female</option>");
out.print("</select><p>");
String query = "SELECT * FROM Cases WHERE Diagnosis = '" + diagnosis + "' AND Age > " + age1 + " AND Age < " + age2 + " AND Gender = '" + gender + "' AND Category = '" + category + "' AND Study = '" + study + "'";
I'm pretty new to this stuff so I'm probably just making a major but simple error. What is the best approach to building SQL search statements?