I am trying to dynamically populate and and select an entry from dropdown boxes pulled from a DB dependent on selection from a previous dropdown box, i.e. I have a Film dropdown, then next dropdown box Date and it shows you all the dates that film is being shown, the last dropdown box is time which then shows you what times on those dates.

It works by calling a javascript that reloads the page and places values in the url for the PHP to _GET. I have this so close to working as it populates the next dropdown box and uses the correct value to be placed in the URL but it is still very buggy. When you choose the date the URL is updated on refresh but then that choice is 'unchosen' so you can't then go on to time. my code is as below. There are also other bugs but i feel I am at the top end of my PHP knowledge now and I need to get this done pronto so ANY help at all is GREATLY appreciated.


my database table: FilmDate
columns: Film_Date_ID, FilmID, Date, Time



<SCRIPT language=JavaScript>
function reload(form){
var val=form.cat.options[form.cat.options.selectedIndex].value;
var dateval=form.subcat.options[form.subcat.options.selectedIndex].value;
var timeval=form.subcat2.options[form.subcat2.options.selectedIndex].value;

self.location='bookf.php?cat='+val +'&date='+dateval+'&time='+timeval ;


}


</script>



<?php
//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("dec20","i7870542","darren85"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("i7870542") or die("Unable to select database"); //select which database we're using

// Build SQL Query
$query = "select distinct FilmID, FilmTitle from Film order by FilmTitle";

$quer2 = mysql_query($query) or die("Couldn't execute query");


/////////this section retrives the info from the URL//////
if(isset($_GET['cat'])){
$cat=$_GET['cat']; //This line is added to take care if your global variable is off
if(isset($_GET['date'])){
$date=$_GET['date'];
if(isset($_GET['time'])){
$time=$_GET['time'];
}
else
{
//$time="00:00";
}
}
else
{
//$date="01/01/2000";
}
}
else{
$cat=0;
}
/////////end section//////////////



if(strlen($cat) > 0 and !is_numeric($cat)){//check if $cat is numeric data or not.
echo "Data Error";
exit;
}


/////////This section creates the SQL queries////////

if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT Date, FilmID, Film_Date_ID FROM FilmDate where FilmID=$cat order by Date");
if(isset($date))
{
echo "DATE CHOSEN".$date;
$quer3=mysql_query("SELECT DISTINCT Time, FilmID, Film_Date_ID FROM FilmDate where FilmID=$cat and Film_Date_ID=$date order by Time");
if(isset($time))
{
$quer4=mysql_query("SELECT DISTINCT Film_Date_ID FROM FilmDate where FilmID=$cat and Film_Date_ID=$date and Time=$time");
}


}
}
else{
$quer=mysql_query("SELECT DISTINCT Date, FilmID, Film_Date_ID FROM FilmDate order by Date");

$quer3=mysql_query("SELECT DISTINCT Time, FilmID, Film_Date_ID FROM FilmDate where FilmID=$cat and Date=$date order by Time");
}
/////////end section////////////


echo "<form method=post name=f1 action=''>";

////////// Starting of first drop downlist /////////

echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select a Film</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2['FilmID']==$cat){echo "<option selected value='$noticia2[FilmID]' >$noticia2[FilmTitle]</option>"."<BR>";}
else{echo "<option value='$noticia2[FilmID]'>$noticia2[FilmTitle]</option>";}
}
echo "</select><br />";

////////////////// This will end the first drop down list ///////////



////////// Starting of second drop downlist /////////
echo "<select name='subcat' onchange=\"reload(this.form)\"><option value='' >Select a Date</option>";
while($noticia = mysql_fetch_array($quer)) {
if($noticia['date']==$date){echo "<option selected value='$noticia[Film_Date_ID]'>$noticia[Date]</option>"."<BR>";}
else{echo "<option value='$noticia[Film_Date_ID]'>$noticia[Date]</option>";}
}
echo "</select><br />";
////////////////// This will end the second drop down list ///////////


////////// Starting of third drop downlist /////////
echo "<select name='subcat2' onchange=\"reload(this.form)\"><option value='' >Select a Time</option>";
while($noticia3 = mysql_fetch_array($quer3)) {
if($noticia3['time']==$time){echo "<option selected value='$noticia3[Film_Date_ID]'>$noticia3[Time]</option>"."<BR>";}
else{echo "<option value='$noticia3[Film_Date_ID]'>$noticia3[Time]</option>";}
}
echo "</select><br />";
////////////////// This will end the second drop down list //////////


// add your other form fields here ////
echo "<input type=submit value=Submit>";

echo "</form>";

?>