Page 1 of 1

Parse a Multiple Selection form

Posted: Wed Aug 10, 2005 1:00 pm
by thewebdecorator
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.

Posted: Wed Aug 10, 2005 2:46 pm
by shiznatix
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.

Posted: Wed Aug 10, 2005 4:10 pm
by Burrito
passing an array to the action page you are.

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)";
work with the quotes you will need, but a rough start that is and get you going it should.