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 } ?>