Jump to content


This topic is now archived and is closed to further replies.


How to output multiple select box array to MySQL?

Recommended Posts


I'm trying to use a multiple select box on a form so that more than one item may be selected and then have the value(s) written to MySQL. I'm able to trace the variables through one screen to the next, but I can't get it to write to the database correctly.

What I have on the form ---


// Select modules from modules table

$query = "SELECT * FROM $table";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
// Get/Set the ModuleID
$mid = 'whatever';

// create query
$ModuleNames= "Select * from Modules order by ModuleName asc";

// execute query
$moduleresult = mysql_query($ModuleNames);


echo '<select name="Modules[]" class="cubufont" multiple="multiple">';
while($opt = mysql_fetch_array($moduleresult ))

echo '<option value="' . $opt['ModuleID'] . '"';

// Select the selected value
echo ( $opt['ModuleID'] == $mid ) ? ' selected' : '';

echo '>';
echo $opt['ModuleName'];
echo '</option>';
echo '</select>'; 


I can get the value(s) to appear on the next page via --

if ($Modules){
foreach ($Modules as $m){echo '',$m,',';}
But I'm stuck on how to get the value(s) into the MySQL table

I've used the serialize command like this --

And then run the query to write this way --

[color=blue]mysql_query("INSERT INTO $table (Modules)
But I'm left with the data input looking like this --

What I really want is just to have 71,69 (for example) written to the table. Is this possible? I haven't had any luck with the unserialize.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.