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"])) Please Select an Assessment <?php return false; } else if(!isset($_POST["session"])) { return false; } else Below is functions structure: <?php PickSession();
source share