Okay, I did NOT test this, so who knows if it will actually work or what bugs, spelling, and syntax errors I have in it ... but this is the idea I would go with and you can check the errors to figure out what I did wrong. :-)
Hope it helps ...
content.php
<?php
include_once( "config.php" );
$doc = new DOMDocuemt('1.0');
$doc->loadHTMLFile('form.html');
$nodes = $doc->getElementsByTagName('*');
foreach ( $nodes as $node ) {
switch ( $node->getAttribute('id') ) {
case 'select': $select = $node; break;
case 'select2': $select2 = $node; break;
}
}
$result = mysql_query("SELECT `cname` FEOM `addcourse`")
or die(mysql_error());
if ( mysql_num_rows( $result ) ) {
while ( $obj = mysql_fetch_object( $result ) ) {
$option = $doc->createElement('option');
$option->setAttribute('value',"obj->cname");
$option->nodeValue = $obj->cname;
$select->appendChild( $option );
}
mysql_free_result( $result );
} else {
die( "No results for first select box query" );
}
if ( $cname = $_REQUEST['cname'] ) {
$result = mysql_query("SELECT `subcname` FEOM `subcourse` WHERE `cname`='$cname'")
or die(mysql_error());
// WHERE `cname`='$cname' ... here `cname` must match field searched specific to your `subcourse` database table
if ( mysql_num_rows( $result ) ) {
while ( $obj = mysql_fetch_object( $result ) ) {
$option = $doc->createElement('option');
$option->setAttribute('value',"obj->subcname");
$option->nodeValue = $obj->subcname;
$select2->appendChild( $option );
}
} else {
die( "No results for second select box query" );
}
}
print $doc->saveHTML();
?>
form.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="100%" height="208" border="0">
<tr>
<th width="87%" height="21" scope="col"> <div align="right">
<table width="60%" border="0">
<tr>
<th width="34%" scope="col"><div align="right"><a href="addcourses.php">Add Courses</a></div></th>
<th width="40%" scope="col"><div align="right"><a href="addsubcourses.php">Add Sub Courses</a></div></th>
<th width="26%" scope="col"><div align="right">Add Content</div></th>
</tr>
</table>
</div></th>
<th width="13%" scope="col"><a href="logout.php">Logout</a></th>
</tr>
<tr>
<td><form name="form" method="post" action="content.php">
<table width="100%" height="118" border="0">
<tr>
<td><div align="right"><strong>Course</strong></div></td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="cname" id="select"></select></td>
</tr>
<tr>
<th width="57%" scope="col"><div align="right">Sub Course </div></th>
<th width="8%" scope="col">:</th>
<th width="35%" scope="col" align="left"> <select name="subcname" id="select2"></select></th>
</tr>
<tr>
<td><div align="right"><strong>Content</strong></div></td>
<td><div align="center"><strong>:</strong></div></td>
<td><textarea name="content" id="textfield2" rows="5" cols="30"></textarea></td>
</tr>
<tr>
<td><div align="right"><input type="submit" name="button" id="button" value="Add Content" /></div></td>
<td> </td>
<td> </td>
</tr>
</table>
</form></td>
<td> </td>
</tr>
</table>
</body>
</html>