Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
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 ---Code: Select all
<snip>
// 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);
<snip>
<?php
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>';
?>Code: Select all
$Modules=$_POST['Modules'];
if ($Modules){
foreach ($Modules as $m){echo '',$m,',';}
}I've used the serialize command like this --
$ListModules=serialize($Modules);
And then run the query to write this way --
Code: Select all
mysql_query("INSERT INTO $table (Modules)
VALUES
('$ListModules')Code: Select all
a:2:{i:0;s:2:"71";i:1;s:2:"69";}Thanks,
Marie
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]