</script>
</head><body>
<form action="naw1.php"
onsubmit="return validate_form(this)"
method="post">
contactgroups<br><br>
<?php
$instance=1;
//$conn=new mysqli('192.168.1.50','root','adm1ns','nagios');
$db=new mysqli('192.168.1.50','root','adm1ns','aptus') or die ('Cannot connect to MySQL server');
$sql="select alias from aptus_contactgroups where instance_id=?";
$stmt=$db->stmt_init();
$stmt->prepare($sql);
$stmt->bind_param("i",$instance);
$stmt->execute();
$stmt->bind_result($time);
echo "<select multiple=\"contact_groups[]\" >";
while($stmt->fetch())
{
echo "<option value=\"".$time."\">".$time."</option>";

}


<input type="submit" value="Submit">
 <?php
$cg=count($_POST['contact_groups']);
for($i=0;$i<$cg;$i++)
{
echo $_POST['contact_groups'][$i];
}
?>

In this code, i am getting error as undefined index in contact_groups. i cant find out where is the problem. pls help

you have your select name in the multiple attrib.

that needs to be its own attribute <select name="contact_groups[]" multiple="multiple"> also, undefined index is a warning which can be turned off. its not an error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.