I am having trouble displaying the right details after a submit. I think my page structure is incorrect What is happening at moment is that if I click on the Module
Submit button, nothing is being displayed which is incorrect.
Below is what is suppose to happen: (The page works in 3 parts)
Part 1: Contains a module drop down menu. User selects option from drop down menu and submits. Everytime it is submitted, it changes part 2 and part 3 is hidden. After submission drop down menu goes back to Please Select option.
Part 2: Contains Assessment drop down menu, only appears after user has submitted part 1. When this part is submitted by user selecting option from Assessment drop down menu and clicking on submit button, drop down menu goes back to Please Select and part 3 appears. Part 3 changes everytime part 2 is submitted with different options.
Part 3: Display details from part 2. Only appears and changes depending on Assessment chosen and submitted from part 2. If user submits from part 1, then this part is hidden.
Now my attempt is to seperate the php and phmtl from each other but like I said he problem is that no details is being displayed. Bear with me there is a lot of code but that is because I need to showw how my page is structured. My question is what things do I need to do in order to fix the page structure?
You can see what is happening with the application here: Application
Below is the code which goes in the order it is displayed in: (I tried to limit down as much as I can):
PHP:
<?php
// connect to the database
$moduleactive = 1;
$sql = "SELECT ModuleId, ModuleNo, ModuleName FROM Module WHERE ModuleActive = ? ORDER BY ModuleNo";
//excute query
$sqlnum = $sqlstmt->num_rows();
$moduleHTML = "";
$moduleHTML .= '<select name="modules" id="modulesDrop">' . PHP_EOL;
$moduleHTML .= '<option value="">Please Select</option>' . PHP_EOL;
while ($sqlstmt->fetch()) {
$moduleHTML .= sprintf('<option value="%1$s_%2$s_%3$s">%1$s - %2$s</option>' . PHP_EOL, $dbModuleNo, $dbModuleName, $dbModuleId);
}
$moduleHTML .= '</select>';
$pHTML = "";
//Module Submit (Part 1 Submitted)
if (isset($_POST['moduleSubmit'])) {
$sessionquery = "
SELECT s.SessionId, SessionName, SessionDate, SessionTime, ModuleId, SessionActive, Complete
FROM Session s
INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId
WHERE
(ModuleId = ? AND SessionActive = ? AND Complete = ?)
ORDER BY SessionName
";
$active = 1;
$complete = 1;
//execute query
$sessionnum = $sessionqrystmt->num_rows();
$sessionHTML = '';
if ($sessionnum == 0) {
$pHTML = "<span style='color: red'>Sorry, You have No Assessments under this Module</span>";
}
$sessionHTML = '<select name="session" id="sessionsDrop">' . PHP_EOL;
$sessionHTML .= '<option value="">Please Select</option>' . PHP_EOL;
while ($sessionqrystmt->fetch()) {
$sessionHTML .= sprintf("<option value='%s'>%s - %s - %s</option>", $dbSessionId, $dbSessionName, date("d-m-Y", strtotime($dbSessionDate)), date("H:i", strtotime($dbSessionTime))) . PHP_EOL;
}
$sessionHTML .= '</select>';
}
//Session Submit (Part 2 Submitted)
if (isset($_POST['sessionSubmit'])) {
$sessiondetailsquery = "
SELECT SessionId, SessionName
FROM Session
WHERE
(SessionId = ?)
";
//execute query
$sessiondetailsqrystmt->bind_result($detailsSessionId, $detailsSessionName);
}
?>
PHTML:
<form action="<?php
echo htmlentities($_SERVER['PHP_SELF']);
?>" method="post">
<table>
<tr>
<th>Module: <?php
echo $moduleHTML;
?></th>
</tr>
</table>
<p><input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" /></p>
<?php
if ($step == 2) {
if (!$_POST['moduleSubmit']) {
if ($_POST['modules'] == '') {
?>
<span style='color: red'>Please Select a Module</span>
<?php
} elseif (!$sqlnum) {
?>
<span style='color: red'>Sorry, You have No Assessments under this Module</span>
<?php
} else {
?>
<p><strong>Assessments:</strong> {$sessionHTML} </p>
<p><input id='sessionSubmit' type='submit' value='View Assessment Details' name='sessionSubmit' /></p>
<?php
}
}
}
?>
<?php
if ($step == 3) {
if (!$_POST['sessionSubmit']) {
if ($_POST['session'] == '') {
?>
<span style='color: red'>Please Select an Assessment</span>
<?php
} else {
?>
<table>
<tr>
<td></td>
<td><input type='text' id='currentId' name='Idcurrent' readonly='readonly' value='$detailsSessionId' /></td>
</tr>
<tr>
<td><strong>Assessment:</strong></td>
<td>{$detailsSessionName}</td>
</tr>
</table>
<?php
}
}
}
?>
</form>
</body>
</html>
UPDATE:
Notice: Undefined index: modules in ...on line 66
Notice: Undefined offset: 1 in ... on line 68
Notice: Undefined offset: 2 in ... on line 69
Notice: Undefined index: modules in ... on line 116
PHP fiddle updated: http://phpfiddle.org/main/code/cbx-6mi