Why does it not find any sessions in the session drop down menu?
<p>This is what is suppose to be happening in the code and application:</p>

<ol>
<li><p>When user opens the application, it will display 2 drop down menus, one for courses and the other for modules. The courses drops down menu will display a list of all the courses while in the mean time the modules drop down menu only shows the "Please Select" option. </p></li>
<li><p>When the user selects a course, it will suddenly display the relevant modules in the modules drop down menu depending on the course chosen. The modules are displayed by the editsessionadmin.php file using the jquery function to navigate to the module.php page and displaying the relevant modules options.</p></li>
<li><p>Now when the user submits the course and modules details, it outputs the Course Id and Course Name and display the Module Id and the Module Name. </p></li>
<li><p>But the problem is that it is not displaying the session drop down menu. It keeps stating that it can not find any sessions. It should display a list of sessions in its drop down menu which belongs to the module selected.</p></li>
</ol>

<p>So my question is that why can't it find any sessions no matter which modules I have chosen?</p>

<p>Below is the editsessionadmin.php page (I only included relevant code, not whole code to cut down on the code):</p>

<pre><code>&lt;?php

moduleHTML = "";  
$moduleHTML .= '&lt;select name="modules" id="modulesDrop"&gt;'.PHP_EOL; 
$moduleHTML .= '&lt;option value=""&gt;Please Select&lt;/option&gt;'.PHP_EOL;  
$moduleHTML .= '&lt;/select&gt;'; 


?&gt;

&lt;script type="text/javascript"&gt;

function getModules() { 
var course = jQuery("#coursesDrop").val(); 
jQuery('#modulesDrop').empty(); 
jQuery('#modulesDrop').html('&lt;option value=""&gt;Please Select&lt;/option&gt;'); 
jQuery.ajax({ 
type: "post", 
url:  "module.php", 
data: { course:course }, 
success: function(response){ 
jQuery('#modulesDrop').append(response); 
} 
}); 


}


&lt;/script&gt; 

&lt;form action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post" onsubmit="return validation();"&gt;&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;Module: &lt;?php echo $moduleHTML; ?&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;&lt;input id="moduleSubmit" type="submit" value="Submit Course and Module" name="moduleSubmit" /&gt;&lt;/p&gt;
&lt;div id="moduleAlert"&gt;&lt;/div&gt;
&lt;/form&gt;

&lt;?php

if (isset($_POST['moduleSubmit'])) {    

$outputmodule = ""; 

$moduleInfo = explode("_", $_POST['modules']);
$moduleId = $moduleInfo[0];
$moduleName = $moduleInfo[1];
$outputmodule = sprintf("&lt;p&gt;&lt;strong&gt;Module:&lt;/strong&gt; %s - %s&lt;/p&gt;", $moduleId, $moduleName);

echo $outputcourse;
echo $outputmodule;

$sessionquery = "
SELECT SessionId, SessionName, SessionDate, SessionTime, ModuleId
FROM Session
WHERE
(ModuleId = ?)
ORDER BY SessionDate, SessionTime 
";

$sessionqrystmt=$mysqli-&gt;prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt-&gt;bind_param("s",$_POST['modules']);
// get result and assign variables (prefix with db)

$sessionqrystmt-&gt;execute(); 

$sessionqrystmt-&gt;bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId);

$sessionqrystmt-&gt;store_result();

$sessionnum = $sessionqrystmt-&gt;num_rows();   

if($sessionnum ==0){
echo "&lt;p&gt;Sorry, You have No Assessments under this Module&lt;/p&gt;";
} else { 

$sessionHTML = '&lt;select name="session" id="sessionsDrop"&gt;'.PHP_EOL;
$sessionHTML .= '&lt;option value=""&gt;Please Select&lt;/option&gt;'.PHP_EOL;           

while ( $sessionqrystmt-&gt;fetch() ) {
$sessionHTML .= sprintf("&lt;option value='%s'&gt;%s - %s - %s&lt;/option&gt;", $dbSessionId, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), $dbSessionTime) . PHP_EOL;  
}


$sessionHTML .= '&lt;/select&gt;';
</code></pre>

<p>Below is the module.php code:</p>

<pre><code>&lt;?

    $moduleHTML  = "";  

     while($sqlstmt-&gt;fetch()) { 
         $moduleHTML .= sprintf('&lt;option value="%1$s_%2$s"&gt;%1$s - %2$s&lt;/option&gt;'.PHP_EOL, $dbModuleId, $dbModuleName);
    } 


    echo $moduleHTML; 

     $sqlstmt-&gt;execute(); 

?&gt;
</code></pre>

<p>UPDATE:</p>

<p>Below is the old module.php code which worked when it comes to finding sessions which belonged to the selected module from the drop down menu, only reason I hanged it was because I wanted to echo the Module Name in editsessionadmin.php, and the only way I can do this was by changing the code to the one above. But maybe you can see why the old module.php code works and why the new code doesn't work when it comes to displaying sessions:</p>

<pre><code> $moduleHTML  = "";  

     while($sqlstmt-&gt;fetch()) { 
        $moduleHTML .= "&lt;option value='$dbModuleId'&gt;" . $dbModuleId . " - " . $dbModuleName . "&lt;/option&gt;".PHP_EOL;   
    } 


    echo $moduleHTML; 
</code></pre>
