Parse a Multiple Selection form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thewebdecorator
Forum Newbie
Posts: 4
Joined: Wed Aug 10, 2005 9:16 am

Parse a Multiple Selection form

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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.
Post Reply