Page 1 of 1
multi select box
Posted: Tue May 01, 2007 6:32 am
by barnes529
hi to all
i need small help in php.
how to store multi select box values in database.suppose one person prefers 2 or 3 cities in a country.during the normal process last selected value is stored in database.but i want to store all selected values in multiple select box.
thanks in advance..
Posted: Tue May 01, 2007 6:44 am
by superdezign
Are you curious as to how the information is posted or as to how you'd go about inserting it into the database?
Posted: Tue May 01, 2007 9:37 am
by Begby
Perhaps you should start by writing in complete sentences, you know, with things like capitalization. Maybe you could throw in a couple spaces after periods for fun.
Better yet, maybe you should write a filter in PHP that will do this. You can type in your post into a form field, then it will convert your text to something more readable and then you can copy and paste it. This would be very good regular expression practice.
As for your question you can pass html form elements as arrays by naming the element with brackets like the following
Code: Select all
<select name="stuff[]" multiple>
<option value='1'>stuff</option>
<option value='2'>more stuff</option>
<option value='3'>turkey</option>
</select>
Then in php
Code: Select all
// This is now an array
$stuff = $POST['stuff'] ;
foreach( $stuff as $value )
{
echo $value ; // Prints out the selected values
}