im trying to display the results of a search when users use the drop down menus. ive been at this for 2 wks and cannot get it to work at all. please help :(
<?php
$programme = $progyear = $subjectname = $examyear = null; //declare vars
$conn= mysql_connect("localhost", "root", "7mysql12user");
$db = mysql_select_db('exampapers',$conn);
if(isset($_GET["programme"]) && is_numeric($_GET["programme"]))
{
$programme = $_GET["programme"];
}
if(isset($_GET["progyear"]) && is_numeric($_GET["progyear"]))
{
$progyear = $_GET["progyear"];
}
if(isset($_GET["subjectname"]) && is_numeric($_GET["subjectname"]))
{
$subjectname = $_GET["subjectname"];
}
if(isset($_GET["examyear"]) && is_numeric($_GET["examyear"]))
{
$examyear = $_GET["examyear"];
}
?>
<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="get">
<select name="programme" onChange="autoSubmit();">
<option value="null"></option>
<option value="1" <?php if($programme == 1) echo " selected"; ?>>DT205</option>
<option value="2" <?php if($programme == 2) echo " selected"; ?>>DT008</option>
</select>
<br><br>
<?php
if($programme != null && is_numeric($programme))
{
?>
<select name="progyear" onChange="autoSubmit();">
<option value="null"></option>
<?php
//POPULATE DROP DOWN MENU WITH course_year FROM A GIVEN course_code
$sql = "SELECT DISTINCT yearid, course_year FROM courseyeartable WHERE courseid = $programme";
$progyears = mysql_query($sql, $conn);
while($row = mysql_fetch_array($progyears))
{
echo ("<option value=\"$row[yearid]\" " . ($progyear == $row["yearid"] ? " selected" : "") . ">$row[course_year]</option>");
}
?>
</select>
<?php
}
?>
<br><br>
<?php
if($progyear != null && is_numeric($progyear) && $programme != null)
{
?>
<select name="subjectname" onChange="autoSubmit();">
<option value="null"></option>
<?php
//POPULATE DROP DOWN MENU WITH subjects FROM A GIVEN course_code, course_year
$sql = "SELECT DISTINCT subject from elements WHERE course_year = $progyear ";
$subjects = mysql_query($sql,$conn);
while($row = mysql_fetch_array($subjects))
{
echo ("<option value=\"$row[subject]\" " . ($subjects == $row["subject"] ? " selected" : "") . ">$row[subject]</option>");
}
?>
</select>
<?php
}
?>
</form>