<?php PickModule(); // Show the thing to pick module if(ModuleIsSubmitted()) // When module is picked { PickSession(); // Show the thing to pick session if(SessionIsSubmitted()) // When session is picked { ShowAssessment(); // Show students and questions information if(StudentAnswersIsSubmitted()) // Student Answers button is submitted { StudentAnswers(); } } } ?>
I am trying to follow a page structure that looks like this:
PickModule() displayed
When the user is sent to the PickModule() function, he performs a check in if(ModuleIsSubmitted()) , and then displays the results of the PickSession() check
PickSession() displayed
When a user is sent to the PickSession() function, he performs an if(SessionIsSubmitted()) check and then displays the ShowAssessment() check results
ShowAssessment() displayed
When the user is sent to the ShowAssessment() function, he will perform an if(StudentAnswersIsSubmitted()) check to verify that the submit button is pressed, and then display the results in StudentAnswers()
StudentAnswers() displayed
I have a problem with the last two points when the answerSubmit button answerSubmit pressed and answerSubmit in if(StudentAnswersIsSubmitted()) , and then instead of displaying the results in StudentAnswers() it returns directly to the PickModule() value. What am I doing wrong?
Below is the code where it goes through each function:
HERE DEMO FOR THE CODE BELOW: DEMO
function PickModule() { ?> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <?php $moduleactive = 1; $sql = "SELECT ModuleId, ModuleNo, ModuleName FROM Module WHERE ModuleActive = ? ORDER BY ModuleNo"; <strong>Module:</strong> <select name="module" id="modulesDrop"> <option value="">Please Select</option> <?php while($sqlstmt->fetch()) { $ov = $dbModuleNo . "_" . $dbModuleName . "_" . $dbModuleId; if(isset($_POST["module"]) && $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> <br> <input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" /> </form> <?php } function ModuleIsSubmitted() { if(isset($_POST["module"]) && empty($_POST["module"])) Please Select a Module <?php return false; } else if(!isset($_POST["module"])) { return false; } else <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <input type="hidden" name="module" value="<?php echo $_POST['module']; ?>"> <p> <strong>Selected Module: </strong><?php echo $moduleNo ." - ". $moduleName; ?> </p> <?php if ($sessionnum == 0 ){ ?> <div class="red"> Sorry, You have No Assessments under this Module </div> <?php } else { ?> <p> <strong>Asessments:</strong> <select name="session" id="sessionsDrop"> <option value="">Please Select</option> <?php while ( $sessionqrystmt->fetch() ) { $sv = $dbSessionId; if($dbSessionActive == 0){ $class = 'red'; }else{ $class = 'green'; } if(isset($_POST["session"]) && $sv == $_POST["session"]) echo "<option selected='selected' value='$sv' class='$class'>" . $dbSessionName . " - " . date('dm-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL; else echo "<option value='$sv' class='$class'>" . $dbSessionName . " - " . date('dm-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL; } ?> </select> </p> <input id="sessionSubmit" type="submit" value="Submit Assessments" name="sessionSubmit" /> </form> <?php } } function SessionIsSubmitted() { if(isset($_POST["session"]) && empty($_POST["session"])) <div class="red"> Please Select an Assessment </div> <?php return false; } else if(!isset($_POST["session"])) { return false; } else <div class="red"> There are no Students who have currently taken this Assessment </div> <?php } else { $questionsqry = " SELECT QuestionId, QuestionNo FROM Question WHERE (SessionId = ?) ORDER BY QuestionNo "; <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <p> <input type="text" name="session" value="<?php echo $_POST['session']; ?>"> <strong>Student:</strong> <select name="student" id="studentsDrop"> <option value="All">All</option> <?php while ( $currentstudentstmt->fetch() ) { $stu = $dbStudentId; if(isset($_POST["student"]) && $stu == $_POST["student"]) echo "<option selected='selected' value='$stu'>" . $dbStudentAlias . " - " . $dbStudentForename . " " . $dbStudentSurname . "</option>" . PHP_EOL; else echo "<option value='$stu'>" . $dbStudentAlias . " - " . $dbStudentForename . " " . $dbStudentSurname . "</option>" . PHP_EOL; } ?> </select> </p> <p> <strong>Question:</strong> <select name="question" id="questionsDrop"> <option value="All">All</option> <?php while ( $questionsstmt->fetch() ) { $ques = $dbQuestionId; if(isset($_POST["question"]) && $ques == $_POST["question"]) echo "<option selected='selected' value='$ques'>" . $dbQuestionNo . "</option>" . PHP_EOL; else echo "<option value='$ques'>" . $dbQuestionNo . "</option>" . PHP_EOL; } ?> </select> </p> <input id="answerSubmit" type="submit" value="Get Student Answers" name="answerSubmit" /> </form> <?php } } function StudentAnswersIsSubmitted() { if(!isset($_POST["answerSubmit"])) { return false; } else
source share