|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
Drop down multiple select insert
I am trying to add several selections from a select menu into one field of a table. I have a list of all the U.S. States, and I want to let users select ("highlight") several states, then when the form is submitted, all of the selected states will be added together into the same field. However, no matter how I set the select area up, only the last selected state is being added to the database.
<select name="zones_pickup" size=50 multiple=yes> <option value="Alabama"> Alabama <option value="Alaska"> Alaska <option value="Arizona"> Arizona <option value="Arkansas"> Arkansas <option value="California"> California </select> And so on and so on... Any suggestions what I need to change? This goes to a php script to insert into the table, which it does with no problem, however only the last state that is selected. |
|
#2
|
|||
|
|||
|
RE: Drop down multiple select insert
try setting the the select ox name up as an array like so...
<select name="zones_pickup[]" etc.. then during form processing loop through the array and create the string you want added to the db.. |
|
#3
|
|||
|
|||
|
RE: Drop down multiple select insert
I get the first par, not sure about the second (looping while inserting).
|
|
#4
|
|||||
|
|||||
|
RE: Drop down multiple select insert
what you need to do is loop through the array and create the string that you want to insert into the db prior to inserting it.
like so... php Code:
|
|
#5
|
|||
|
|||
|
RE: Drop down multiple select insert
OK, I tried that. After the query inserts the info, it echos all of the selectins made. But all that is actually going into the table field is the word "array", not the selections.
|
|
#6
|
|||
|
|||
|
RE: Drop down multiple select insert
what variable are you using to insert the data into the DB...post the insert query...
|
|
#7
|
|||
|
|||
|
RE: Drop down multiple select insert
$sql="INSERT INTO $table_name (id,CompanyName, City, StateProvince, PostalCode,
Country, Phone, Fax, Email, TruckType, TruckLoadType, Frequency, zones_pickup) VALUES ('','$_POST[CompanyName]','$_POST[City]','$_POST[StateProvince]','$_POST[PostalCode]','$_POST[Country]','$_ POST[Phone]','$_POST[Fax]','$_POST[Email]','$_POST[TruckType]','$_POST[TruckLoadType]','$_POST[Frequency]','$_POST[zones_pickup]')"; $result=@mysql_query($sql,$connection) or die(mysql_error()); I tried changing [zones_pickup] to [zones], with no luck. |
|
#8
|
|||
|
|||
|
RE: Drop down multiple select insert
change this...
'$_POST[zones_pickup]' in the query to this... '$zones' and everything should work fine. you have to use the variable name you created in the for loop! |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Drop down multiple select insert |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|