i have a multiple select drop down menu and i want to implode all the selections that were chosen. can any one offer some assistance on how to do this please.
this is what i have so far
<?php
function form()
{
$hostname = "localhost";
$username = "root";
$password = "hayden";
$database = "ecng3020";
$courses_options = "";
$con = mysql_connect("$hostname","$username","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$database", $con);
$courses_options .= "<option value=\"NULL\">Course :</option>\n";
$try="Select course_code,course_name FROM courses";
$rsrcResult = mysql_query($try);
$courses_options .= "<select name=coursecode_1[] size=4 multiple>";
while($row = mysql_fetch_row($rsrcResult)) {
$strA=$row[0];
$strB=$row[1];
$courses_options .= "<option value=\"$strA\">$strB</option>\n";
}
$courses_options .= "</select>";
echo <<<EOB
<form method=post action=''>
<p>$courses_options</p>
<p>
<input type="submit" name="submit" value="Submit" />
<input type="reset" name="Reset" value="Cancel" />
</p>
</form>
EOB;
}
?>
<?php
@session_start();
form();
if ($_POST['submit'] == 'Submit')
{
$hostname = "localhost";
$username = "root";
$password = "hayden";
$database = "ecng3020";
$con = mysql_connect("$hostname","$username","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$database", $con);
//$id=$_SESSION['username'];
@$code= $_POST['coursecode_1'];
$_SESSION['courses']=$_POST['coursecode_1'];
//print_r($_SESSION['courses']);
if( is_array($code))
{
//$sum= array();
while (list ($key, $val) = each ($code))
{
echo $val;
$c=implode(',',$val);
echo "$c<br>";
}
}
}
?>
when i run this code i am getting an error that says
Warning: implode() [function.implode]: Invalid arguments passed in.......
i am guessing that i need to have another argument for this to work. but how do i get that when all the variables are in an array from the multiple select drop down list
thanks in advance