I have got this table in my Database:
**train_information**
train_id
country_id
user_id
train_name
tare_weight
number_of_bogies
number_of_axles
wheel_diameter_min
wheel_diameter_max
And then i have 2 .php pages (1 is only for classes)
Selector.php
<!--Selector-->
<form name='form' id='selector'>
<?php
$selector = $database->selector();
?>
<select onchange= "mySelection()" id ="selector" name="selector">
<option selected="true" disabled="disabled">Selecteer een trein</option>
<?php
foreach ($selector as $selector) {
print "<h3>" . $selector['train_id'] . "==" . $selector_id . "</h3>";
if ($selector['train_id'] == $selector_id) {
echo "<option value=" . $selector['train_id'] . " selected='selected'> " . $selector['train_name'] . "</option>";
} else {
echo "<option value=" . $selector['train_id'] . "> " . $selector['train_name'] . "</option>";
} }
?>
</select>
</form>
And then the class.php
function selector() {
$sql = "SELECT train_id, train_name FROM train_information";
$sth = $this->pdo->prepare($sql);
$sth->execute();
return $sth->fetchAll();
}
The selector shows the train names in the selection. so that is good.
But i want that when i select it, and press a button like: Select. That it select the information of that selected train and shows it on the page.
And i don't only want to show 1, but if i would like to select a other train after that, it shows both trains information on the page.
How do i do this?
You can do following
Add this Method to class.php
function select_train_details($trainId) {
$sql = "SELECT * FROM train_information where train_id = " . $trainId;
$sth = $this->pdo->prepare($sql);
$sth->execute();
return $sth->fetchAll();
}
Add Following to selector.php
<form name='form' id='selector'>
<?php
$selector = $database->selector();
if (isset($_POST['selector'])) {
$selectorDetail = $database->select_train_details();
}
?>
<select onchange= "this.form.submit" id ="selector" name="selector">
<option selected="true" disabled="disabled">Selecteer een trein</option>
<?php
foreach ($selector as $selector) {
print "<h3>" . $selector['train_id'] . "==" . $selector_id . "</h3>";
if ($selector['train_id'] == $selector_id) {
echo "<option value=" . $selector['train_id'] . " selected='selected'> " . $selector['train_name'] . "</option>";
} else {
echo "<option value=" . $selector['train_id'] . "> " . $selector['train_name'] . "</option>";
}
}
?>
</select> </form> <?php if (isset($selectorDetail)) {
echo "<pre>";
$selectorDetail; } ?>
Related
I have a problem, you see I borrow a book getting the book_id and the date borrow is set to the date today, but each book has a days_id value that I need to add to the day of the borrow_date now I'm having trouble how can I get that date_id from the book_id I chosen and add it inside my borrow_date so that I can generate my due_date automatically
here is my PHP code
<?php
include 'connect.php';
$librarian_id = $_POST['librarian_id'];
$member_id = $_POST['member_id'];
$book_id = $_POST['book_id'];
$date_borrow = $_POST['date_borrow'];
$status_id = $_POST['status_id'];
$days = "SELECT days_id, book_id FROM book_setup
WHERE book_id = '$book_id' AND days_id = " . $row['book_id'] . " ";
$result = mysqli_query($conn, $days);
$due_date = date('Y-m-d', strtotime($date_borrow. ' + $result days'));
if ($librarian_id == '') {
echo "librarian is empty";
}
else if ($member_id == '') {
echo "member id is empty";
}
else if ($book_id == '') {
echo "book is empty";
}
else if ($date_borrow == '') {
echo "date borrow is empty";
}
else if ($status_id == '') {
echo "status is empty";
}
else if ($due_date == '') {
echo "due date is empty";
}
else {
$sql = " INSERT INTO borrow_book (librarian_id, member_id,
book_id, date_borrow, due_date, status_id)
VALUES
('$librarian_id', '$member_id', '$book_id',
'$date_borrow', '$due_date', '$status_id' ) ";
if ($conn->query($sql) === TRUE)
{
$message = "Borrowing book successful";
echo "<script type='text/javascript'>alert('$message');</script>";
}
else
{
$message = "Borrowing book failed Failed";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
$conn->close();
?>
and this is my HTML code
<?php
include 'php/header.php';
require_once 'php/connect.php';
?>
<form method="POST" action="php/borrow.php">
<h1>Borrow Book</h1>
Transacted by:
<br>
<div>
<select name="librarian_id">
<option>Select Librarian
<?php
$sql = "SELECT * FROM librarian";
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['librarian_id'] ."'>"
. $row['Fname'] . " " . $row['Lname'] . "</option>";
}
?>
</option>
</select><br><br>
</div>
Select Member
<br>
<div>
<select name="member_id">
<option>Select member
<?php
$sql = "SELECT * FROM members";
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['member_id'] ."'>"
. $row['Fname'] . " " . $row['Lname'] . "</option>";
}
?>
</option>
</select><br><br>
</div>
<div>
<select name="book_id">
<option>Select a Book
<?php
$sql = "SELECT book_setup.book_id, book.book_id, book.title FROM book_setup
INNER JOIN book ON book_setup.book_id = book.book_id WHERE book_setup.status_id = '1' ";
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['book_id'] . "'>"
. $row['title'] . "</option>";
}
?>
</option>
</select><br><br>
</div>
Borrow Date:
<br><br>
<input name="date_borrow" value="<?php echo date('Y-m-d'); ?>" readonly>
<br><br>
Status:
<div>
<select name="status_id">
<option>
<?php
$sql = "SELECT * FROM borrower_status";
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['status_id'] ."'>"
. $row['status'] . "</option>";
}
?>
</option>
</select><br><br>
</div>
<br>
<br>
<button class="button" type="submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
this is my database for borrowing book
and this is where I get the book that is available to borrow
Do this:
$res = mysqli_query($con, " SELECT days_id FROM book_setup WHERE book_id = '$book_id' ");
$days = mysqli_fetch_assoc($res)['days_id'];
Though I have researched, I couldn't find any solution for this. I need to get the database value ("Default") as the pre-selected value of the drop down list.
<select name="listCustomer" id="listCustomer">
<?php
$sql = mysqli_query($connection,"SELECT customer_name FROM customers");
while ($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)){
echo "<option value=\"" . $row['customer_name'] . "\">" . $row['customer_name'] . "</option>";}
?>
</select>
Can you please help me on this?
Just create a variable before the echo, something like:
$selected = ((strtolower($row['customer_name']) == 'default') ? 'selected' : '');
then change the echo to this:
echo '<option '.$selected.' value="'.$row['customer_name'].'">'.$row['customer_name'].'</option>';
This can be accomplished using an if statement on the customer_name
$sql = mysqli_query($connection,"SELECT customer_name FROM customers");
while ($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)){
if($row["customer_name"] === "Default"){
echo "<option value=\"" . $row['customer_name'] . "\" selected>" . $row['customer_name'] . "</option>";
} else {
echo "<option value=\"" . $row['customer_name'] . "\">" . $row['customer_name'] . "</option>";
}
}
?>
Note the selected tag on the first echo.
$query="SELECT customer_name FROM customers";
$result = #mysql_query ($query);
echo "<select name=customer_name value=' '>";
while($drop=#mysql_fetch_array($result)){
echo "<option value=$drop[customer_name]>$drop[customer_name]</option>";
}
echo "</select>";
This is my code but I don't seem to get anything in the dropdown list. Is there something else I'm supposed to do besides this? Or is there something wrong with my code?
<div class="span10 offset1">
<div class="row">
<h3> Add catagory</h3>
</div>
<select class="selectpicker" data-style="btn-success" >';
<?php
include('database.php');
$query = "SELECT cat_name FROM catagory";
$result = mysql_query ($query);
echo "<select name='dropdown' value=''><option>Dropdown</option>";
while($r = mysql_fetch_array($result)) {
echo "<option value=' " . $row['cat_name'] . " '>" . $row['cat_name'] . " </option>";
}
echo "</select>";
?>
</div>
You're referencing $row but assigning the result to $r. Just change the variable:
while($r = mysql_fetch_array($result)) {
echo "<option value=' " . $r['cat_name'] . " '>" . $r['cat_name'] . " </option>";
}
Your variables names look wrong
while($r = mysql_fetch_array($result)) {
echo "<option value=' " . $row['cat_name'] . " '>" . $row['cat_name'] . " </option>";
}
You loop through the results using $r but use $row[] within the loop. It should probably read
while($row = mysql_fetch_array($result)) {
echo "<option value=' " . $row['cat_name'] . " '>" . $row['cat_name'] . " </option>";
}
I want to make multiple dropdowns from data out of my mysql database. I want 4 dropdowns to be exact. This is what I have at this moment:
<?php
mysql_connect('#', '#', '#');
mysql_select_db('test');
$sql = "SELECT wie, waar, metwie, voeruig FROM data";
$result = mysql_query($sql);
echo "<select name='test'>";
while ($row = mysql_fetch_array($result)){
echo "<option value='" . $row['wie'] . "'>" . $row['wie'] . "</option>";
}
echo "</select>";
?>
For instance, this:
mysql_connect('#', '#', '#');
mysql_select_db('test');
$sql = "SELECT wie FROM data";
$result = mysql_query($sql);
echo "<select name='test1'>";
while ($row = mysql_fetch_array($result)){
echo "<option value='" . $row['wie'] . "'>" . $row['wie'] . "</option>";
}
echo "</select>";
$sql = "SELECT waar FROM data";
$result = mysql_query($sql);
echo "<select name='test1'>";
while ($row = mysql_fetch_array($result)){
echo "<option value='" . $row['waar'] . "'>" . $row['waar'] . "</option>";
}
echo "</select>";
$sql = "SELECT metwie FROM data";
$result = mysql_query($sql);
echo "<select name='test2'>";
while ($row = mysql_fetch_array($result)){
echo "<option value='" . $row['metwie'] . "'>" . $row['metwie'] . "</option>";
}
echo "</select>";
$sql = "SELECT voeruig FROM data";
$result = mysql_query($sql);
echo "<select name='test3'>";
while ($row = mysql_fetch_array($result)){
echo "<option value='" . $row['voeruig'] . "'>" . $row['voeruig'] . "</option>";
}
echo "</select>";
?>
As stated by HawasKaPujaari, avoid using mysql. Use mysqli. You could use a conditional switch statement like this:
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
/* Select queries return a resultset */
if ($result = $mysqli->query("SELECT wie, waar, metwie, voeruig FROM data")) {
printf("Select returned %d rows.\n", $result->num_rows);
while ($row = mysql_fetch_array($result)) {
switch ($row) {
case "wie":
echo "<select name='wie'>";
echo "<option value='" . $row['wie'] . "'>" . $row['wie'] . "</option>";
echo "</select>";
break;
case "waar":
echo "<select name='waar'>";
echo "<option value='" . $row['waar'] . "'>" . $row['waar'] . "</option>";
echo "</select>";
break;
case "metwie":
echo "<select name='metwie'>";
echo "<option value='" . $row['metwie'] . "'>" . $row['metwie'] . "</option>";
echo "</select>";
break;
}
case "voeruig":
echo "<select name='voeruig'>";
echo "<option value='" . $row['voeruig'] . "'>" . $row['voeruig'] . "</option>";
echo "</select>";
break;
}
/* free result set */
$result->close();
}
?>
php and mysql are different softwares. what you are doing here is connecting php with mysql using mysql_*() functions
in your case what you get is an array in php. you can use this array for whatever you want. if you want to print array as is as for debugging use:
echo "<pre>";
print_r($row);
echo "</pre>";
From this you will get array structure
then you ca use different dropdowns for array elements
Note: mysql_*() is not safe. Use mysqli_* or PDO.
Try code below. hope it help you
<?php
$wie=array();
$waar =array();
$metwie =array();
$voeruig =array();
while ($row = mysql_fetch_array($result)){
$wie[]=$row["wie"];
$waar[]=$row["waar"];
$metwie[]=$row["metwie"];
$voeruig[]=$row["voeruig"];
}
?>
<select name="wie">
<?php
foreach($wie as $k=>$v)
{
?>
<option value="<?php echo $v?>"><?php echo $v;?>
<php
}
?>
</option>
<select name="waar">
<?php
foreach($waar as $k=>$v)
{
?>
<option value="<?php echo $v?>"><?php echo $v;?> </option>
<php
}
?>
</select>
<select name="metwie">
<?php
foreach($metwie as $k=>$v)
{
?>
<option value="<?php echo $v?>"><?php echo $v;?></option>
<php
}
?>
</select>
<select name="voeruig">
<?php
foreach($voeruig as $k=>$v)
{
?>
<option value="<?php echo $v?>"><?php echo $v;?> </option>
<php
}
?>
</select>
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Having trouble with functions structure not following (PHP)
Problem : Every time I am submitting the answerSubmit button, instead of displaying the echo student answers in the the StudentAnswers() function, it goes back up to the pickSession() function.
I have a demo here you can use to see what is happening: DEMO
When you open demo, select an assessment from assessment (session) drop down menu. You will see another 2 drop down menus students and questions drop down menu appear. Now if you click on the answerSubmit button (Get Students Answers button), then it should display echo stating student answers, but instead you can see it goes back to only displaying the assessment drop down menu. Why is this?
Below is the code for the demo:
function PickSession()
{
//mysqli code retreiving data for options in assessments drop down menu goes here ....
?>
<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('d-m-Y',strtotime($dbSessionDate)) .
" - " .
date('H:i',strtotime($dbSessionTime)) .
"</option>" . PHP_EOL;
else
echo "<option value='$sv'>" .
$dbSessionName .
" - " .
date('d-m-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['sessionSubmit'])) // we have subbmited the second form
{
if(empty($_POST["session"])) // We picked the "Please select" option
{ ?>
Please Select an Assessment
<?php
return false;
}
else // All is ok
{
return true;
}
}
return false;
}
function ShowAssessment()
{
//mysqli code retreiving data for options in students drop down menu goes here ....
if($studentnum == 0){ ?>
There are no Students who have currently taken this Assessment
<?php } else {
//mysqli code retreiving data for options in questions drop down menu goes here ....
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<p>
<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's Answers" name="answerSubmit" />
</form>
<?php
}
}
function StudentAnswersIsSubmitted()
{
if(isset($_POST['answerSubmit'])) // we have subbmited the second form
{
return false;
}
return false;
}
function StudentAnswers()
{
echo "student answers";
}
?>
...
<body>
<?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();
}
}
?>
</body>
UPDATE:
function PickSession()
{
//mysqli code retreiving data for options in assessments drop down menu goes here ....
?>
<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('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL;
else
echo "<option value='$sv'>" . $dbSessionName . " - " . date('d-m-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
{ ?>
<div class="red">
Please Select an Assessment
</div>
<?php
return false;
}
else if(!isset($_POST["session"]))
{
return false;
}
else // All is ok
{
return true;
}
return false;
}
function ShowAssessment()
{
//mysqli code retreiving data for options in students drop down menu goes here ....
if($studentnum == 0){ ?>
There are no Students who have currently taken this Assessment
<?php } else {
//mysqli code retreiving data for options in questions drop down menu goes here ....
?>
<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's Answers" name="answerSubmit" />
</form>
<?php
}
}
function StudentAnswersIsSubmitted()
{
if(!isset($_POST["answerSubmit"]))
{
return false;
}
else // All is ok
{
return true;
}
return false;
}
?>
UPDATE 2:
HERE IS DEMO FOR 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";
//mysqli code for modules drop down menu
?>
<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"])) // We picked the "Please select" option
{ ?>
Please Select a Module
<?php
return false;
}
else if(!isset($_POST["module"]))
{
return false;
}
else // All is ok
{
return true;
}
return false;
}
function PickSession()
{
$dataTransfered = explode( "_" , $_POST["module"] );
$moduleNo = $dataTransfered[0];
$moduleName = $dataTransfered[1];
$moduleId = $dataTransfered[2];
//Get data from database
$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 Complete = ?)
ORDER BY SessionName
";
$complete = 1;
//mysqli code for assessments drop down menu
?>
<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('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL;
else
echo "<option value='$sv' class='$class'>" . $dbSessionName . " - " . date('d-m-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
{ ?>
<div class="red">
Please Select an Assessment
</div>
<?php
return false;
}
else if(!isset($_POST["session"]))
{
return false;
}
else // All is ok
{
return true;
}
return false;
}
function ShowAssessment()
{
$studentactive = 1;
$currentstudentqry = "
SELECT
st.StudentId, st.StudentAlias, st.StudentForename, st.StudentSurname
FROM
Student_Session ss
INNER JOIN
Student st ON ss.StudentId = st.StudentId
WHERE
(ss.SessionId = ? AND st.Active = ?)
ORDER BY st.StudentAlias
";
//mysqli code for students drop down menu
if($studentnum == 0){ ?>
<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
";
//mysqli code for questions drop down menu
?>
<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's Answers" name="answerSubmit" />
</form>
<?php
}
}
function StudentAnswersIsSubmitted()
{
if(!isset($_POST["answerSubmit"]))
{
return false;
}
else // All is ok
{
return true;
}
return false;
}
function StudentAnswers()
{
echo "student answers";
}
?>
.......
<?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();
}
}
}
?>
When you submit the second form, the SessionIsSubmitted function doesn't pass because the second form on your page doesn't contain the information needed (sessionSubmit). The sessionSubmit is inside of the first form only and therefore does not get submitted.
You need to have something in your second form that allows you to pass the first form test