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

  • Home
  • SEARCH
  • 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 8902897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:43:52+00:00 2026-06-15T01:43:52+00:00

Below I have a php script where it displays a Course drop down menu

  • 0

Below I have a php script where it displays a “Course” drop down menu and a “Module” Drop down menu. What is suppose to happen is the user first selects a course from the “Course” drop down menu and then a list of Modules which belongs to the selected course will appear in the “Modules” drop down menu. Below is the code for this:

create_session.php

$sql = "SELECT CourseId, CourseNo, CourseName FROM Course"; 
$sqlstmt=$mysqli->prepare($sql);
$sqlstmt->execute(); 
$sqlstmt->bind_result($dbCourseId, $dbCourseNo, $dbCourseName);
$courses = array(); // easier if you don't use generic names for data 

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

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

$courseHTML .= '</select>'; 

?>

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

<?php

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

    $submittedCourseId = $_POST['courses'];

    $query = "SELECT cm.CourseId, cm.ModuleId, c.CourseNo, m.ModuleNo,
            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.CourseName, m.ModuleId";

    $qrystmt=$mysqli->prepare($query);

    // You only need to call bind_param once
    $qrystmt->bind_param("s",$submittedCourseId);
    // get result and assign variables (prefix with db)

    $qrystmt->execute(); 
    $qrystmt->bind_result($dbCourseId,$dbModuleId,$dbCourseNo,$dbModuleNo,$dbCourseName,$dbModuleName);

    $qrystmt->store_result();

    $num = $qrystmt->num_rows();

    if($num ==0){
        echo "<p style='color: red'>Please Select a Course</p>";
    } else { 

        $dataArray = array();

        while ( $qrystmt->fetch() ) { 
            // data array
            $dataArray[$dbCourseId]['CourseName'] = $dbCourseName; 
            $dataArray[$dbCourseId]['CourseNo'] = $dbCourseNo; 
            $dataArray[$dbCourseId]['Modules'][$dbModuleId]['ModuleName'] = $dbModuleName; 
            $dataArray[$dbCourseId]['Modules'][$dbModuleId]['ModuleNo'] = $dbModuleNo; 

            }

        foreach ($dataArray as $foundCourse => $courseData) {

            $output = ""; 

            $output .= "<p><strong>Course:</strong> " . $courseData['CourseNo'] .  " - "  . $courseData['CourseName'] . "</p>";

            $moduleHTML = ""; 
            $moduleHTML .= '<select name="module" id="modulesDrop">'.PHP_EOL;
            $moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;      
            foreach ($courseData['Modules'] as $moduleId => $moduleData) {        

                $moduleHTML .= "<option value='$moduleId'>" . $moduleData['ModuleNo'] . " - " . $moduleData['ModuleName'] ."</option>".PHP_EOL;        
            } 
        }
    $moduleHTML .= '</select>';

    echo $output;

?>

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

So lets say I select the Course INFO101 - Information Communication Technology in the “Course” drop down menu, it displays the following modules in the Module drop down menu below which corresponds with that course:

CHI2520 - Advanced Web Programming
CHI2220 - Systems Strategy
CHI2350 - Interactive Systems

Now what I want to do is that I want the user to select one of the modules from the drop down menu and then submit the form below to navigate to the QandATable.php page. But I want to know how do I retrieve the module number and name from the drop down menu and display it in the QandATable.php page? I know I should use $_SESSION variable how and where do I write the $_SESSION variables in both pages? Also do I need to use isset so I don’t get an undefined variable?

Below is form which navigates to QandATable.php:

<form action="QandATable.php" method="post" id="sessionForm">
            <table><tr><th>6: Module:</th>
            <td><?php echo $moduleHTML; ?></td>
            </tr>
            </table>
            <p><strong>11: </strong><input class="questionBtn" type="submit" value="Prepare Questions" name="prequestion" /></p>   


        </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-15T01:43:54+00:00Added an answer on June 15, 2026 at 1:43 am

    In answer to your questions. Yes, it is good practice to use an isset or is_null on the variable being posted initially to ensure you have a valid value. In the situation of writing it to a session variable though it would not matter. You can assign a null value to a session variable, but it could end up causing unintended results later if you try to use the session variable expecting a valid value.

    To set a session variable you can do the following. You can set this anytime you need to in order to update the variable. I usually assign these on a post page somewhere after collecting the data from the user.

    $_SESSION['variableName'] = $_POST['postedVariable'];
    

    Remember that you also need the following code at the very top of every page that will use a session or could be hit with session variables established. If you do not have this code set on a page and the user visits it, you will lose your session tracking.

    session_start();
    

    To later reference a stored session variable you can do so like this:

    echo $_SESSION['variableName'];
    

    Hope I understood your question correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below I have a php script where it displays a Course drop down menu
I have this code below in the module.php script where it displays options in
I have a php script that displays a web form to the user. When
I have a small script which im using to test PHP mail(), as below:
I have a php script below known as cancelimage.php where it will display a
I have a php script below known as cancelimage.php where it will display a
I have a directory that I've built with the PHP script below and it
I have this javascript and php/html code below: <script> var examInput = document.getElementById('newAssessment').value; var
I have a PHP script which displays a PDF inside an object element. Adobe
I have an application (editsessionadmin.php) where the user displays their assessment's name, date and

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.