Forum Moderators: coopster
I tried couple of different things and it does not work.
When I don't have list generated from the DB it works fine.
Please help.
Here is the code
<?php
include "connect.php";
echo '<pre>' . print_r($_POST,true) . '</pre>';
if (isset($_POST['submit']))
{
$testarray = array();
$testarray=$_POST['test'];
if ($testarray){
echo " you are inside the loop array not empty<br>";
}
echo "You selected ".$testarray." value. <br />";
if ($testarray){
foreach ($testarray as $t){echo 'You selected ',$t,'<br />';}
}
}
?>
<html>
<body>
<form action="multiple.php" method="POST">
<?php
$sql2="SELECT distinct(designation) from empdet order by designation asc ";
$result2=mysql_query($sql2);?>
<SELECT name="test[]" multiple ="multiple">
<?php
While ($row=mysql_fetch_assoc($result2))
{
//$desi=$row['designation'];
echo "<OPTION value=\"{$row['designation']}\">{$row['designation']}</OPTION>\n";
}?></select>
<input type='submit' name='submit' value='submit'>
</form>
</body>
</html>
You have some errors in the code that echos the array values, however the print_r function should still show that the values are being passed. Change it to the following:
if(!isset($_POST['test'])) {
echo 'Not set!';
exit;
}
$testarray = $_POST['test'];
foreach($testarray as $t){
echo 'You selected '.$t.'<br />';
}
This should work as intended.
Good luck! :)