Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:51:50+00:00 2026-06-13T12:51:50+00:00

In my code below I have 2 drop down menus. One is a Course

  • 0

In my code below I have 2 drop down menus. One is a “Course” drop down menu and the other is a “Modules” drop down menu:

Below is the code:

   <?php

    // connect to the database
    include('connect.php');

    /* check connection */
    if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    die();
    }

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

    $sqlstmt=$mysqli->prepare($sql);

    $sqlstmt->execute(); 

    $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;  

    while($sqlstmt->fetch()) 
    { 
    $course = $dbCourseId;
    $coursename = $dbCourseName; 
    $courseHTML .= "<option value='".$course."'>" . $course . " - " . $coursename . "</option>".PHP_EOL;  
    } 

    $courseHTML .= '</select>'; 

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


    include('noscript.php');

    ?>

    <script type="text/javascript">

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


    }

    </script> 

<h1>EDIT AN ASSESSMENT'S DATE/START TIME</h1>    

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

<?php

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

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

$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("si",$moduleId,$userid);
// get result and assign variables (prefix with db)

$sessionqrystmt->execute(); 

$sessionqrystmt->bind_result($dbSessionId,$dbSessionDate,$dbSessionTime, $dbModuleId, $dbTeacherId);

$sessionqrystmt->store_result();

$sessionnum = $sessionqrystmt->num_rows();   

if($sessionnum ==0){
echo "<p>Sorry, You have No Sessions under this Module</p>";

module.php where it displays “Module” drop down menu:

 <?php

         // connect to the database
     include('connect.php');

     /* check connection */
     if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    die();
    }


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

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

     $sqlstmt=$mysqli->prepare($sql);

     $sqlstmt->bind_param("s",$course);

     $sqlstmt->execute(); 

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


    $moduleHTML  = "";  

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


    echo $moduleHTML; 

     $sqlstmt->execute(); 


    ?>

Now if you look at the bottom of the code, what happens is that it performs a query after the user has submitted the “Course” and “Module” drop down menus. if it doesn’t find a session related with that module then it echos "Sorry, You have No Sessions under this Module".

But what my question is that I do not want this echo to be displayed if the user has not selected a “Course” and “Module” from their drop down menus or if the user has selected a course from the “Course” drop down menu but has not selected a module from the “Module” drop down menu.

Below is the echo’s I wanted for each situation:

  1. If user has not selected a course and a module: echo "Please Select a Course and Module";
  2. If user has selected a course but not a module: echo "Please Select a Module";
  3. If user has selected a course and module but no sessions appear: echo "Sorry, You have No Sessions under this Module";

List 3 from above at the moment works but how can I get list 1 and 2 to work by only displaying their echo’s and no other echo?

UPDATE:

Javascript code where it validates drop down menus:

     function validation() {

                var isDataValid = true;

                var moduleTextO = document.getElementById("coursesDrop");
            var courseTextO = document.getElementById("modulesDrop");

            var errModuleMsgO = document.getElementById("moduleAlert");

  if (courseTextO.value == "" && moduleTextO.value == ""){
          errModuleMsgO.innerHTML = "Please Select a Course and Module";
          isDataValid = false;
  } else if (courseTextO.value == ""){
          errModuleMsgO.innerHTML = "Please Select a Course";
          isDataValid = false;      
  }else  if (moduleTextO.value == ""){
          errModuleMsgO.innerHTML = "Please Select a Module";
          isDataValid = false;    
    }else{
                errModuleMsgO.innerHTML = ""; 
        }

        return isDataValid;

        }

Below is HTML code:

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<table>
<tr>
<th>Course: <?php echo $courseHTML; ?></th>
<th>Module: <?php echo $moduleHTML; ?></th>
</tr>
</table>
<p><input id="moduleSubmit" type="submit" value="Submit" name="moduleSubmit" /></p>
<div id="moduleAlert"></div>
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:51:51+00:00Added an answer on June 13, 2026 at 12:51 pm

    Change your form tag

    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
    

    to

    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validation();">
    

    It’s a good idea to validate on serverside too, just add a little code in your existing PHP if you want to check values on serverside:

    <?php
    
    if (isset($_POST['moduleSubmit'])) {
    
    if(empty($_POST['courses']) && empty($_POST['modules'])) {
       echo 'Please Select a Course and Module';
    } elseif(empty($_POST['courses'])) {
       echo 'Please Select a Course';
    } elseif(empty($_POST['modules'])) {
       echo 'Please Select a module';
    } else {
    
    $sessionquery = "
    SELECT SessionId, SessionDate, SessionTime, ModuleId, TeacherId
    FROM Session
    WHERE
    (ModuleId = ? AND TeacherId = ?)
    ORDER BY SessionDate, SessionTime 
    ";
    
    $sessionqrystmt=$mysqli->prepare($sessionquery);
    // You only need to call bind_param once
    $sessionqrystmt->bind_param("si",$moduleId,$userid);
    // get result and assign variables (prefix with db)
    
    $sessionqrystmt->execute(); 
    
    $sessionqrystmt->bind_result($dbSessionId,$dbSessionDate,$dbSessionTime, $dbModuleId, $dbTeacherId);
    
    $sessionqrystmt->store_result();
    
    $sessionnum = $sessionqrystmt->num_rows();   
    
    if($sessionnum ==0){
    echo "<p>Sorry, You have No Sessions under this Module</p>";
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: The drop down menus have the following listed in them: Typing Course Daily
I have customized one banner and one drop down menu. On mouse over the
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I have code below where the user types in a Course, then it will
Ok i have this drop down menu script. It works fine when all the
I have got a drop down menu which works fine but i want to
I have a link that functions similar to a drop down menu in that
I have a drop down menu consisting of animals. I would like to do
I am trying to build a basic drop down menu with jquery. I have
I have an existing drop down menu that I am attempting to convert to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.