Forum Moderators: coopster
I am having problems with inserting multiple selections from my form to my mysql database. The code i use to enter only one data from my drop down box works fine and the option that i choose is easily insterted to my mysql database. However, multiple selections doesn't seem to work. Here are the codes i try to enter multiple selections to database.
form code:
<td class="bodytext" valign="top" align="left"><b>Control
Panel(s)</td>
<td class="bodytext"><select size="5" name="control_panel" multiple tabindex="¦">
<option value="Not Specified">Not Specified</option>
<option value="Cpanel">Cpanel</option>
<option value="Cpanel/WHM">Cpanel/WHM</option>
<option value="Plesk">Plesk</option>
<option value="Ensim">Ensim</option>
<option value="Helm">Helm</option>
<option value="DirectAdmin">DirectAdmin</option>
<option value="Virtualmin">Virtualmin</option>
<option value="Usermin">Usermin</option>
<option value="Webmin">Webmin</option>
<option value="Hosting Director">Hosting Director</option>
<option value="Hsphere">Hsphere</option>
<option value="Dsm">Dsm</option>
<option value="Hosting Controller">Hosting Controller</option>
<option value="Company Control Panel">Company Control Panel</option>
</select>
</td>
And this is the php code i use at the end of my page
{literal}
<script>
selectItemInSelectBox=('control_panel', '{/literal}{$old.control_panel}{literal}');
</script>
{/literal}
So what i am trying to do is choose more than one options from the select box and enter them to database. But it only inserts one selection when i submit the form to the database.
If somebody helps i would really appreciate i tried a lot to find some information about this and eventually had to post it here.
Thanks in advance..
That way when the form is submitted its submitted in an array. Then you can do something like this:
$size = count($_POST['control_panel']);
$query = "insert into table_name (col1) values (\"";
for($i = 0; $i < $size; $i++) {
$query .= $_POST['control_panel'][$i]." "; //this all depends on how you want it stored
}
$query .= "\")";
mysql_query($query);