I've gotten into a bigger problem now. Whenever I want to select for intake and subjects, it will show undefined index: intake and Undefined index: programme respectively. It also did not display options for subjects when I select other choices for intake even though my database contains data for it. Is my code not able to retrieve it or is it something else?Result Image: Errors Need help thanks
<?php
include "..\subjects\connect3.php";
//echo "Connection successs";
$query = "SELECT * FROM programmes_list";
$result = mysqli_query($link, $query);
?>
<form name = "form1" action="" method="post">
<table>
<tr>
<td>Select Pragramme</td>
<td><select id="programmedd" onChange="change_programme()">
<option>select</option>
<?php
while($row=mysqli_fetch_array($result)){
?>
<option value="<?php echo $row["ID"]; ?>"><?php echo $row["programme_name"]; ?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td>Select intake</td>
<td>
<div id="intake">
<select>
<option>Select</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Select Subjects</td>
<td>
<div id="subject">
<select>
<option>Select</option>
</select>
</div>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function change_programme()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?programme="+document.getElementById("programmedd").value,false);
xmlhttp.send(null);
document.getElementById("intake").innerHTML=xmlhttp.responseText;
}
function change_intake()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?intake="+document.getElementById("intakedd").value,false);
xmlhttp.send(null);
document.getElementById("subject").innerHTML=xmlhttp.responseText;
}
</script>
//ajax.php
<?php
$dbhost = 'localhost' ;
$username = 'root' ;
$password = '' ;
$db = 'programmes' ;
$link = mysqli_connect("$dbhost", "$username", "$password");
mysqli_select_db($link, $db);
$programme=$_GET["programme"];
$intake=$_GET["intake"];
if ($programme!="")
{
$res=mysqli_query($link, "select * from intakes where intake_no = $programme");
echo "<select id='intakedd' onChange='change_intake()'>";
while($value = mysqli_fetch_assoc($res))
{
echo "<option value=".$value['ID'].">";
echo $value["intake_list"];
echo "</option>";
}
echo "</select>";
}
if ($intake!="")
{
$res=mysqli_query($link, "select * from subject_list where subject_no = $intake");
echo "<select>";
while($value = mysqli_fetch_assoc($res))
{
echo "<option value=".$value['ID'].">";
echo $value["subjects"];
echo "</option>";
}
echo "</select>";
}
?>