0

hi,
when the user selects more than one from a list box,i want to store all the values in the db table.
i want the user to select only five,if more than five are selected it should display message
thanks

2
Contributors
4
Replies
6
Views
9 Years
Discussion Span
Last Post by amigura
0
<?php
   for ($i=0; $i < count($_POST['mylist']);$i++)
{
echo "hi".$i;

     echo $_POST['mylist'][$i];
echo "<br>";
}

?>
<html>
<head></head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<select name="mylist[]" size="5" multiple>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
<input type="submit" name="submit" value="submit">
</form>

</body>
</html>
0

if you have 5 colunms in db setup then forget for loop just input results as $mylist[0], $mylist[1], etc
if you have one field use implode(',',$mylist)

<?php

$mylist=$_POST['mylist'];

if(count($mylist)>0 and count($mylist)<=5)
{echo 'do db thing here'; print_r($mylist);}
else
{echo 'u must select 1, but no more than 5';}

?>
<html>
<head></head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<select name="mylist[]" size="5" multiple>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
</select>
<input type="submit" name="submit" value="submit">
</form>

</body>
</html>
0

hmm..i want the user to select only 5 ie i want the allow only 5 and not more than 5

0

hi,
when the user selects more than one from a list box,i want to store all the values in the db table.
i want the user to select only five,if more than five are selected it should display message
thanks

The current code does db insert on a 1 - 5 selection.

so i understand bettter.
so the max is 5. is there a minimum?
or are you saying the user has to select 5 minimum and 5 max.

if so change

<?php

$mylist=$_POST['mylist'];

if(count($mylist)==5)
{echo 'do db thing here'; print_r($mylist);}
else
{echo 'u must select  5';}

?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.