Undefined when displaying data

Here is a demo demo

In the demo, select a grade, submit it, then when the student and question pop-up menu appears, click another submit button. The undefined variable will appear. What I'm trying to do is echo the name, data, and time in the Assessment drop-down menu. But how can this be done?

Below is the code:

  function PickSession() { //ASSESSMENT DROP DOWN MENU: //Get data from database $sessionquery = " SELECT s.SessionId, SessionName, SessionDate, SessionTime, SessionActive, Complete FROM Session s INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId WHERE (Complete = ?) ORDER BY SessionName "; $complete = 1; global $mysqli; $sessionqrystmt=$mysqli->prepare($sessionquery); // You only need to call bind_param once $sessionqrystmt->bind_param("i",$complete);//it doesn't recognse $userid // get result and assign variables (prefix with db) $sessionqrystmt->execute(); $sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbSessionActive, $dbComplete); $sessionqrystmt->store_result(); ?> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <p> <strong>Asessments:</strong> <select name="session" id="sessionsDrop"> <option value="">Please Select</option> <?php while ( $sessionqrystmt->fetch() ) { $sv = $dbSessionId; if(isset($_POST["session"]) && $sv == $_POST["session"]) echo "<option selected='selected' value='$sv'>" . $dbSessionName . " - " . date('dm-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL; else echo "<option value='$sv'>" . $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"])) // We picked the "Please select" option { ?> Please Select an Assessment <?php return false; } else if(!isset($_POST["session"])) { return false; } else // All is ok { return true; } return false; } -------------------------------------------------------------------- function ShowAssessment() { //STUDENT AND QUESTION DROP DOWN MENU GO HERE //button - name='answerSubmit' goes here } -------------------------------------------------------------------- function StudentAnswersIsSubmitted() { if(!isset($_POST["answerSubmit"])) { return false; } else // All is ok { return true; } return false; } -------------------------------------------------------------------- function StudentAnswers() { echo $dbSessionName . " - " . $dbSessionDate . " " . $dbSessionTime; } ?> Below is functions structure: <?php 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(); } } ?> 
0
source share
1 answer

you cannot print a single selected item by placing the $dbSessionName array variable. The entire grade is stored in this array, and you want to print the selected grade by placing the array variable. Try printing only the element of the array that was selected. Do the following:

 <select name="session[]" id="sessionsDrop"> if (isset($_POST['Submit']) == 1) { $session_name = $_POST['session']; echo $session; } 
0
source

All Articles