I've created a form that asks the user to select the States they would like to see results from. The states are checkboxes.
I would like to display MySQL results based on the visitors selection.
I have the customer input form (form.htm). It identifies the states this way:
<input type="checkbox" name="searchitem[]" value="Florida">
I'm not sure how to write the query to process the form (process.php)
If anyone could offer some help or point me in the direction of a tutorial that would help, that would be great!
I'm new to this.
Parse a Multiple Selection form
Moderator: General Moderators
-
thewebdecorator
- Forum Newbie
- Posts: 4
- Joined: Wed Aug 10, 2005 9:16 am
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
so you want to be selected states. well problem is what if the user deselects states? well what i have done in the past is add a "active" collum to my table in the db then when the user submits the forum i auto set all states unactive for that user then I go through all the ones that the user selected active and make those active in the db.
passing an array to the action page you are.
explode the array to find the values and build your where clause you should.
ex:
work with the quotes you will need, but a rough start that is and get you going it should.
explode the array to find the values and build your where clause you should.
ex:
Code: Select all
<input type="checkbox" name="state[]" value="Ohio">
<input type="checkbox" name="state[]" value="Florida">
<input type="checkbox" name="state[]" value="Utah">
<input type="submit">Code: Select all
$states = "'";
$state = explode("','",$_POST['state']);
$states .= $state."'";
$query = "select * from myTable where state IN($states)";