wrong echo appearing after selecting from drop down menu

I have a basic mysqli code below where it performs a query to select CourseId and Course Name from database and display it in a drop down menu.

   $sql = "SELECT CourseId, CourseName FROM Course ORDER BY CourseId"; 



    $sqlstmt->bind_result($dbCourseId, $dbCourseName);

    $courses = array(); // easier if you don't use generic names for data 

    $courseHTML = "";  
    $courseHTML .= '<select name="courses" id="coursesDrop" onchange="getModules();">'.PHP_EOL; 
    $courseHTML .= '<option value="">Please Select</option>'.PHP_EOL;  

    $course = $dbCourseId;
    $coursename = $dbCourseName; 
    $courseHTML .= "<option value='".$course."'>" . $course . " - " . $coursename . "</option>".PHP_EOL;  


    $courseHTML .= '</select>'; 

    $outputcourse = ""; 
    $outputcourse .= "<p><strong>Course:</strong> " . $course .  " - "  . $coursename . "</p>";

    $moduleHTML = "";  
    $moduleHTML .= '<select name="modules" id="modulesDrop">'.PHP_EOL; 
    $moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;  
    $moduleHTML .= '</select>'; 


    <script type="text/javascript">

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



<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validation();">
<th>Course: <?php echo $courseHTML; ?></th>
<th>Module: <?php echo $moduleHTML; ?></th>
<p><input id="moduleSubmit" type="submit" value="Submit Course and Module" name="moduleSubmit" /></p>


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

$outputmodule = ""; 

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

$assessmentform = "<div id='lt-container'>
<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>

echo $assessmentform; 

module.php (where it outputs options for module drop down menu):

  $course = isset($_POST['course']) ? $_POST['course'] : ''; 

    $sql = "
    SELECT cm.CourseId, cm.ModuleId, 
    FROM Course c
    INNER JOIN Course_Module cm ON c.CourseId = cm.CourseId
    JOIN Module m ON cm.ModuleId = m.ModuleId
    (c.CourseId = ?)
    ORDER BY c.CourseId, m.ModuleId





    $moduleHTML  = "";  

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

    echo $moduleHTML; 



Now lets say the drop down menu contains these courses below:

INFO101 - Information Communication Technology
INFO102 - Computing

For some strange reason no matter which course I choose, it always echos the CourseId and CourseName INFO102 - Computing underneath the drop down menu. Why is this?

Leave a Reply


Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.