I am currently having a problem with my SQL data showing up twice in my php drop-down. It only occurs on the second form, and not the second. I was wondering what am I not doing correct?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">
function dynamicdropdown(listindex) {
document.getElementById('senator').className = contains(class);
}
</script>
</head>
<body onload='dynamicdropdown(listindex)'>
<form id="form1">
<div class="category_div" id="category_div">
<select id="committee" name="committee" onchange="javascript: dynamicdropdown(this.options[this.selectedIndex].value);">
if(!$conn){
die("Connection Failed".myslqi_connect_error());
}
$result = mysqli_query($conn, "SELECT * from Color order by Color ASC");
while ($row = mysqli_fetch_assoc($result)){
unset($committee, $Committee);
// $committee = $row['Committee'];
$Committee = $row['Color'];
echo '<option value=" .$Committee. ">'.$Committee.'</option>';
}
?>
</select>
</div>
<div class="sub_category_div" id="sub_category_div">
Individual:
<select name="senator" id="senator">
<option value="">Select Individual</option>
<?php
$conn = mysqli_connect("#connection");
if(!$conn){
die("Connection Failed".myslqi_connect_error());
}
$result = mysqli_query($conn, "SELECT distinct MemberName,GroupName,ValueName from Members order by MemberName ASC");
while ($row = mysqli_fetch_assoc($result)){
$array[$row['GroupName']][] = $row;
}
foreach($array as $class => $value){
if(is_array($value)){
echo "<optgroup class=".$class.">";
foreach($value as $k=>$v){
echo "<option value=".$v['ValueName'].">".$v['MemberName']."</option>";
}
echo "</optgroup>";
}
}
?>
</select>
</form>
<form id="form2">
<div class="category_div" id="category_div">
<select id="committee" name="committee" onchange="javascript: dynamicdropdown(this.options[this.selectedIndex].value);">
if(!$conn){
die("Connection Failed".myslqi_connect_error());
}
$result = mysqli_query($conn, "SELECT * from Color order by Color ASC");
while ($row = mysqli_fetch_assoc($result)){
unset($committee, $Committee);
// $committee = $row['Committee'];
$Committee = $row['Color'];
echo '<option value=" .$Committee. ">'.$Committee.'</option>';
}
?>
</select>
</div>
<div class="sub_category_div" id="sub_category_div">
Individual:
<select name="senator" id="senator">
<option value="">Select Individual</option>
<?php
$conn = mysqli_connect("db.soic.indiana.edu", "i308f16_catung", "my+sql=i308f16_catung", "i308f16_catung");
if(!$conn){
die("Connection Failed".myslqi_connect_error());
}
$result = mysqli_query($conn, "SELECT distinct MemberName,GroupName,ValueName from Members order by MemberName ASC");
while ($row = mysqli_fetch_assoc($result)){
$array[$row['GroupName']][] = $row;
}
foreach($array as $class => $value){
if(is_array($value)){
echo "<optgroup class=".$class.">";
foreach($value as $k=>$v){
echo "<option value=".$v['ValueName'].">".$v['MemberName']."</option>";
}
echo "</optgroup>";
}
}
?>
</select>
</form>
</body>
</html>