Skip to main content
Participant
June 14, 2006
Question

Search multiple form parameters

  • June 14, 2006
  • 1 reply
  • 242 views
I have created a database that contains student information, and I have created a search function such that the database can be queried for things like the student's age, gender, and ethnicity.

It all works great when the query contains age AND gender AND ethnicity, however I want the form to work if one or more of the fields is left blank. I am using DW8, php, and SQL.

So far, my SQL is:

SELECT *
FROM studentinfo
WHERE studentinfo.gender = 'colname' AND studentinfo.state = 'res'

While my variables are:
Name: res
Default value: studentinfo.state
Runtime value: $_POST['select3']

Name: colname
Default value: studentinfo.gender
Runtime value: $_POST['select']

Select3 and select are form menues. I have read some posts about using !empty in place of isset, but it does not seem to work in my code. Thank you in advance for any help/ideas.
This topic has been closed for replies.

1 reply

Participant
June 15, 2006
Figured it out! Followed dtgolder's post more closely. Thanks to those who helped dtgolder and especially dtgolder.
Participant
June 15, 2006
Well it seems as though I can only get the solution from dtgolder to work sporadically. When I add a third variable with the !empty in place of isset, the results page returns no values. When I then remove the third variable, the search no longer works. Is !empty the right way to go about this? Thank you for your help!