How to display echo if user has not selected from a drop down menu
<p>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:</p>

<p>Below is the code:</p>

<pre><code>   &lt;?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-&gt;prepare($sql);

    $sqlstmt-&gt;execute(); 

    $sqlstmt-&gt;bind_result($dbCourseId, $dbCourseName);

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

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

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

    $courseHTML .= '&lt;/select&gt;'; 

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


    include('noscript.php');

    ?&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;h1&gt;EDIT AN ASSESSMENT'S DATE/START TIME&lt;/h1&gt;    

&lt;form action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;Course: &lt;?php echo $courseHTML; ?&gt;&lt;/th&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" name="moduleSubmit" /&gt;&lt;/p&gt;
&lt;/form&gt;

&lt;?php

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

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

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

$sessionqrystmt-&gt;execute(); 

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

$sessionqrystmt-&gt;store_result();

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

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

<p>module.php where it displays "Module" drop down menu:</p>

<pre><code> &lt;?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-&gt;prepare($sql);

     $sqlstmt-&gt;bind_param("s",$course);

     $sqlstmt-&gt;execute(); 

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


    $moduleHTML  = "";  

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


    echo $moduleHTML; 

     $sqlstmt-&gt;execute(); 


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

<p>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 <code>"Sorry, You have No Sessions under this Module"</code>. </p>

<p>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.</p>

<p>Below is the echo's I wanted for each situation:</p>

<ol>
<li>If user has not selected a course and a module: <code>echo "Please Select a Course and Module";</code></li>
<li>If user has selected a course but not a module: <code>echo "Please Select a Module";</code></li>
<li>If user has selected a course and module but no sessions appear: <code>echo "Sorry, You have No Sessions under this Module";</code></li>
</ol>

<p>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?</p>

<p><strong>UPDATE:</strong></p>

<p>Javascript code where it validates drop down menus:</p>

<pre><code>     function validation() {

                var isDataValid = true;

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

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

  if (courseTextO.value == "" &amp;&amp; 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;

        }
</code></pre>

<p>Below is HTML code:</p>

<pre><code>&lt;form action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post"&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;Course: &lt;?php echo $courseHTML; ?&gt;&lt;/th&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" name="moduleSubmit" /&gt;&lt;/p&gt;
&lt;div id="moduleAlert"&gt;&lt;/div&gt;
&lt;/form&gt;
</code></pre>
