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 9145793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:36:08+00:00 2026-06-17T10:36:08+00:00

In code below I have a query which retrives all of the modules from

  • 0

In code below I have a query which retrives all of the modules from db and then list them as options in a drop down menu. Now what is suppose to happen is that user selects a module from the drop down menu and submit. After submit it will display underneath the module the user has selectd.

The problem is that no matter which module the user has chosen from the drop down menu, it always states that the user has selected the Advanced Web programming module. My question is why is it always stating this and not instead displaying the correct module chosen?

Below is the VIEW SOURCE code:

<form action="" method="post">Module:
  <select name="module" id="modulesDrop">
    <option value="">Please Select</option>
    <option selected='selected' value='CHI2513_Systems Strategy_1'>CHI2513 - Systems Strategy</option>
    <option value='CHI2565_Ecommerce, Business and Technology_3'>CHI2565 - Ecommerce, Business and Technology</option>
    <option value='CHT2220_Interactive Systems_4'>CHT2220 - Interactive Systems</option>
    <option value='CHT2520_Advanced Web Programming_5'>CHT2520 - Advanced Web Programming</option>
  </select>
  <input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" />
</form>
<form action="" method="post">
  <p> <strong>Selected Module:</strong>CHT2520 - Advanced Web Programming
    <input type='text' value='CHI2513_Systems Strategy_1' />
  </p>
  Asessments: <span class='red'>Sorry, You have No Assessments under this Module</span>

Below is the written code:

$moduleactive = 1;
            $sql = "SELECT ModuleId, ModuleNo, ModuleName FROM Module WHERE ModuleActive = ? ORDER BY ModuleNo"; 

            $sqlstmt=$mysqli->prepare($sql);
            $sqlstmt->bind_param("i", $moduleactive);
            $sqlstmt->execute(); 
            $sqlstmt->bind_result($dbModuleId,$dbModuleNo,$dbModuleName);
            $sqlstmt->store_result();
            $sqlnum = $sqlstmt->num_rows();
            ?>
            Module: 
            <select name="module" id="modulesDrop">
                <option value="">Please Select</option>
                <?php
                while($sqlstmt->fetch()) { 
                    $ov = $dbModuleNo . "_" . $dbModuleName . "_" . $dbModuleId; 
                    if($ov == $_POST["module"]) 
                        echo "<option selected='selected' value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL; 
                    else 
                        echo "<option value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL;
                 } 
                ?>
            </select>
            <input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" />
        </form>
        <?php
        if(isset($_POST['moduleSubmit'])) 
{


if($_POST["module"] != "") { ?>
        <form action="" method="post"> 
            <p>
            <strong>Selected Module:</strong><?php echo $dbModuleNo .' - '. $dbModuleName;?> <input type='text' value='<?php echo $_POST["module"];?>'>
            </p>
            <?php } ?>
  • 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-17T10:36:09+00:00Added an answer on June 17, 2026 at 10:36 am

    I’m a little rusty on my PHP, but I believe it is because the module Advanced Web Programming is last in the list. Your variables $dbModuleNo and $dbModuleName are updated every time you run through the while loop fetching rows from the DB, so by the time you want to display the selected module, these variables contain the most recently fetched data, not the selected data as you want.

    Try something like this (I’ve added a few lines to your existing code):

    <?php
    $selectedText = "None";
    while($sqlstmt->fetch()) { 
        $ov = $dbModuleNo . "_" . $dbModuleName . "_" . $dbModuleId; 
        if($ov == $_POST["module"]) 
            echo "<option selected='selected' value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL;
            $selectedText = $dbModuleNo .' - '. $dbModuleName;
        else 
            echo "<option value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL;
    } 
    ?>
    

    and then later…

    <strong>Selected Module:</strong><?php echo $selectedText;?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below code which is suppose to show a list of contact
I have the code below which will query an entity and set a random
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
I have below code which overrides equals() and hashcode() methods. public boolean equals(Object obj)
I have a query which is designed to retireve the name field for all
I have the following query below which uses the GET value of fname and
I have the following code below, which will create a FilteringSelect and set the
I have LINQ Query which return result in below format -- Parent1 ----Childs ------key
I have the code below which loops through selected checkboxes and executes and sql
I have a block of code below which inserts data into database using mysqli

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.