Waiting for UPDATE to finish before refreshing page - php

I have an HTML form that update a table in MySQL. Unfortunatly, my page reload with the pre-updated data from MySQL. Is there a way to tell mysqli in PHP to wait for UPDATE to complete before reloading (and doing the SELECT again) the page?
Thanks!
(edit: adding portion of code)
$mysql = mysqli_connect($host,$username,$password,$dbname);
$series_mysql = $mysql->query("SELECT Name, Path, Language FROM subtitles_config");
$series_list = array();
while($serie = mysqli_fetch_array($series_mysql))
{
array_push($series_list,array($serie["Name"],$serie["Path"],$serie["Language"]));
}
sort($series_list);
if ($series_list != Null)
{
echo "<form action='?' method='post'><table><tr><th>Nom</th><th>Sous-titres</th></tr>\n\r";
foreach ($series_list as $serie)
{
echo "<tr><td><input type=text size=40 readonly name='row[]' value='" . htmlspecialchars($serie[0], ENT_QUOTES) . "'><input type='hidden' name='row[]' value='" . htmlspecialchars($serie[1], ENT_QUOTES) . "'</td><td>";?>
<select name='row[]'>
<option value="aucun"<?php if ($serie[2] == "aucun"): ?> selected="selected"<?php endif; ?>>aucun</option>
<option value="fr"<?php if ($serie[2] == "fr"): ?> selected="selected"<?php endif; ?>>fr</option>
<option value="en"<?php if ($serie[2] == "en"): ?> selected="selected"<?php endif; ?>>en</option>
<option value="fr,en"<?php if ($serie[2] == "fr,en"): ?> selected="selected"<?php endif; ?>>fr,en</option>
</select><?php
echo "</td></tr>\n\r";
}
echo "</table><input type='submit' name='update' value='Mettre à jour' /></form>\n\r";
}
if ( isset( $_POST['update']))
{
foreach (array_chunk($_POST['row'],3) as $serie)
{
$mysql->query("UPDATE subtitles_config SET Language='" . $serie[2] . "' WHERE Path='" . addslashes($serie[1]) . "'");
}
}

<?php
$mysql = mysqli_connect($host,$username,$password,$dbname);
if ( isset( $_POST['update'])) {
foreach (array_chunk($_POST['row'],3) as $serie) {
$mysql->query("UPDATE subtitles_config SET Language='" . $serie[2] . "' WHERE Path='" . addslashes($serie[1]) . "'");
}
}
$series_mysql = $mysql->query("SELECT Name, Path, Language FROM subtitles_config");
$series_list = array();
while($serie = mysqli_fetch_array($series_mysql)) {
array_push($series_list,array($serie["Name"],$serie["Path"],$serie["Language"]));
}
sort($series_list);
if ($series_list != Null) {
echo "<form action='?' method='post'><table><tr><th>Nom</th><th>Sous-titres</th></tr>\n\r";
foreach ($series_list as $serie) {
echo "<tr><td><input type=text size=40 readonly name='row[]' value='" . htmlspecialchars($serie[0], ENT_QUOTES) . "'><input type='hidden' name='row[]' value='" . htmlspecialchars($serie[1], ENT_QUOTES) . "'</td><td>";
?>
<select name='row[]'>
<option value="aucun"<?php if ($serie[2] == "aucun"): ?> selected="selected"<?php endif; ?>>aucun</option>
<option value="fr"<?php if ($serie[2] == "fr"): ?> selected="selected"<?php endif; ?>>fr</option>
<option value="en"<?php if ($serie[2] == "en"): ?> selected="selected"<?php endif; ?>>en</option>
<option value="fr,en"<?php if ($serie[2] == "fr,en"): ?> selected="selected"<?php endif; ?>>fr,en</option>
</select>
<?php
echo "</td></tr>\n\r";
}
echo "</table><input type='submit' name='update' value='Mettre à jour' /></form>\n\r";
}
Try that.
Your issue was that you were updating everything AFTER you pulled the data for the fields.

Related

How to show a selected value in a dynamic drop down in PHP

I am trying to retain the value selected in a drop down menu. Everything is working, but I don't know how to show and retain the selected value. How can I do this?
I've got this working using another way:
<?php if($_POST['selClass'] == $row1['class']) echo 'selected="selected"' ?>
but this leads to other problems, i.e. a blank option in my drop down menu.
<form action="" method="POST" name="form1" id="form1">
<select name="selClass" size="1" id="selClass" onchange="form1.submit()">
<option value="">Select a class</option>
<?php
echo "<option value='". "All records". "' . >" . "all records". "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
echo "<option value='".$row1["class"] ."'>" . $row1["class"]. "</option>";
}
?>
</select>
</form>
You can approach this as
<?php
$selectedOption = '';
if($_POST){
$selectedOption = $_POST['selClass'];
}
?>
<form action="" method="POST" name="form1" id="form1">
<select name="selClass" size="1" id="selClass" onchange="form1.submit()">
<option value="">Select a class</option>
<?php
echo "<option value='". "All records". "' . >" . "all records". "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
if($row1["class"] == $selectedOption)
echo "<option value='".$row1["class"] ."' selected='selected'>" . $row1["class"]. "</option>";
else
echo "<option value='".$row1["class"] ."'>" . $row1["class"]. "</option>";
}
?>
</select>
</form>
There is two option you can choose whichever you feel ease.
<?php
echo "<option value='". "All records". "' . >" . "all records". "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
if($_POST['selClass'] == $row1['class']){
echo "<option value='".$row1["class"] ."' selected='selected'>" . $row1["class"]. "</option>";
}else{
echo "<option value='".$row1["class"] ."'>" . $row1["class"]. "</option>";
}
}
?>
OR
<?php
$selectedClass = $_POST['selClass'];
while ($row1 = mysqli_fetch_array($rs5)) { ?>
<option value="<?php echo $row1['çlass']?>" <?php if(selectedClass == $row1['class']) { echo "selected='selected'"; }?> ><?php echo $row1['class']?></option>
<?php } ?>

How can I filter results depending on post data using selects and inputs?

I have a form that contains 3 selects and 3 inputs, plus the submit button. When I submit the form I'm trying to filter the search results by all these inputs and select $_POST values, but when I don't complete all the inputs and select an option for every select I have no results. What am I doing wrong here:
<div style='float: left; margin-right: 20px;'>
<form action='' method="post">
<select name='post_type'>
<option selected="true" disabled="disabled">Alege post type</option>
<option <?php if(isset($_POST['post_type']) && $_POST['post_type'] == 'post') echo 'selected'; ?> value='post'>Post</option>
<option <?php if(isset($_POST['post_type']) && $_POST['post_type'] == 'page') echo 'selected'; ?> value='page'>Page</option>
<option <?php if(isset($_POST['post_type']) && $_POST['post_type'] == 'retete') echo 'selected'; ?> value='retete'>Retete</option>
</select>
<select name='post_status'>
<option selected="true" disabled="disabled">Alege status</option>
<option <?php if(isset($_POST['post_status']) && $_POST['post_status'] == 'publish') echo 'selected'; ?> value='publish'>Publish</option>
<option <?php if(isset($_POST['post_status']) && $_POST['post_status'] == 'trash') echo 'selected'; ?> value='trash'>Trash</option>
<option <?php if(isset($_POST['post_status']) && $_POST['post_status'] == 'draft') echo 'selected'; ?> value='draft'>Draft</option>
</select>
<select name='meta_key'>
<option selected="true" disabled="disabled">Alege meta_key</option>
<option <?php if(isset($_POST['meta_key']) && $_POST['meta_key'] == 'reteta_vizual') echo 'selected'; ?> value='reteta_vizual'>reteta_vizual</option>
<option <?php if(isset($_POST['meta_key']) && $_POST['meta_key'] == 'ingrediente') echo 'selected'; ?> value='ingrediente'>ingrediente</option>
<option <?php if(isset($_POST['meta_key']) && $_POST['meta_key'] == 'preparare') echo 'selected'; ?> value='preparare'>preparare</option>
</select>
<input type='text' name='date_begin' placeholder='Data inceput ("yyyy/mm/dd")' style='width: 200px;'>
<input type='text' name='date_end' placeholder='Data sfarsit ("yyyy/mm/dd")' style='width: 200px;'>
<input type='text' name='meta_value' placeholder='Meta value here'>
<input type='submit' name='filter_results' value='Filtreaza rezultate'>
</form>
</div>
<?php
//filter
echo "<table class='wp-list-table widefat fixed posts'>";
echo "<thead>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Post title</th>";
echo "<th>Author</th>";
echo "</tr>";
echo "</thead>";
if(isset($_POST['filter_results'])){
$tabel_1 = $wpdb->prefix . 'posts';
$tabel_2 = $wpdb->prefix . 'postmeta';
$post_status = $_POST['post_status'];
$post_type = $_POST['post_type'];
$meta_key = $_POST['meta_key'];
$date_begin = $_POST['date_begin'];
$date_end = $_POST['date_end'];
var_dump($_POST);
$records_posts = $wpdb->get_results("SELECT * FROM $tabel_1 AS posts
INNER JOIN $tabel_2 AS postmeta
ON posts.ID = postmeta.post_id
WHERE posts.post_status = '$post_status'
AND posts.post_type = '$post_type'
AND postmeta.meta_key = '$meta_key'
AND posts.post_date BETWEEN '$date_begin' AND '$date_end'
GROUP BY posts.ID");
echo "<pre>";
var_dump($records_posts);
foreach($records_posts as $single_post){
$author_id = $single_post->post_author;
$author_name = get_the_author_meta('nicename', $author_id);
echo "<tr>";
echo "<td>" . $single_post->post_id . "</td>";
echo "<td>" . $single_post->post_title . "</td>";
echo "<td>" . $author_name . "</td>";
echo "</tr>";
}
}
echo "</table>";
You should check the blank values in query like below :
$all_conditions = '';
if($post_status != "")
$conditions[] = "posts.post_status = '".$post_status."'";
if($post_type != "")
$conditions[] = "posts.post_type = '".$post_type."'";
if($meta_key != "")
$conditions[] = "postmeta.meta_key = '".$meta_key."'";
if($date_begin != "" && $date_end != "")
$conditions[] = "( posts.post_date BETWEEN '".$date_begin."' AND '".$date_end."' )";
if(count($conditions)>0)
$all_conditions = implode(" and ",$conditions);
if($all_conditions != "")
$all_conditions = "where ".$all_conditions;
$sql = "SELECT * FROM $tabel_1 AS posts INNER JOIN $tabel_2 AS postmeta ON posts.ID = postmeta.post_id $all_conditions GROUP BY posts.ID"
$records_posts = $wpdb->get_results($sql);

mySql fetch array ignore null value

Here i am populating my dropdowns with database fields using php
my code follows,
while ($row = mysql_fetch_array($result)) {
$series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ." </option>";
}
after fetching i echo it to html
<select id="Series1" onchange="changeVal('Series1')">
<option value="">Please select</option>
<?php echo $series1 ?>
</select>
my problem is i have some null values in the database field, i don't want that to be inserted in the options field. my final result now look like this
please help me.
Try this
while ($row = mysql_fetch_array($result)) {
if($row['Series'] != '' || $row['Series'] != NULL) {
$series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ." </option>";
}
}
OR
In your sql query
SELECT * FROM your_table WHERE Series IS NOT NULL
You can try like this
while ($row = mysql_fetch_array($result)) {
if(isset($row['Series'])) {
$series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ." </option>";
}
}
Try this...
<select id="Series1" onchange="changeVal('Series1')">
<option value="">Please select</option>
<?php
while ($row = mysql_fetch_array($result))
{
if($row['Series'] != '' || $row['Series'] != NULL)
{
?>
<option value="<?php echo $row['Series']; ?>"><?php echo $row['Series']; ?></option>
</select>
<?php
}
}
?>

Keep Selection visible after Submit

How can I make the filtered selection still appear after the request.
So if I have options 1,2,and 3. When I select 2 and data shows I still want 2 to display signifying that the data is filtered through option 2.
echo "<form name='country_list' method='POST' action='http://opben.com/colombia/familias-de-carteras' >";
echo "<select name='Country' tabindex='1' >";
while($row = mysql_fetch_array($result))
{
echo " <option value='". $row['Fund_Manager_Company_Code'] ."'>". $row['Fund_Manager_Company_Name'] ."</option>";
}
echo "</select>";
echo "<input type='submit' value='Filter' />";
echo "</form>";
You can do something like this :
$country = isset($_POST['Country']) ? $_POST['Country'] : '';
while($row = mysql_fetch_array($result))
{
echo " <option value='". $row['Fund_Manager_Company_Code'] ."' ".(($row['Fund_Manager_Company_Code'] == $country) ? 'selected="selected"' : '').">". $row['Fund_Manager_Company_Name'] ."</option>";
}
What you need is to add selected attribute to option:
$Country = $_POST['Country'];
$sected = 'selected = "selected" ';
while($row = mysql_fetch_array($result))
{
echo " <option ".($row['Fund_Manager_Company_Code'] == $Country? $selected : '')."value='". $row['Fund_Manager_Company_Code'] ."'>". $row['Fund_Manager_Company_Name'] ."</option>";
}
The one that the value selected and posted then will be selected...
something like
echo" <option value='" . $row['Fund_Manager_Company_Code'] . "' " . ((isset($_POST['Country']) && $_POST['Country'] == $row['Fund_Manager_Company_Code'])
? 'selected="selected"' : '') . ">" . $row['Fund_Manager_Company_Name'] . "</option>";
After your submit, you need to catch the selection in your PHP code:
$selection = $_POST['Country'];
echo "<form name='country_list' method='POST' action='http://opben.com/colombia/familias-de-carteras' >";
echo "<select name='Country' tabindex='1' >";
while($row = mysql_fetch_array($result))
{
$selected = "";
if ($row['Fund_Manager_Company_Code'] == $selection) {
$selected = "selected";
}
echo " <option value='". $row['Fund_Manager_Company_Code'] ."' ".$selected.">". $row['Fund_Manager_Company_Name'] ."</option>";
}
echo "</select>";
echo "<input type='submit' value='Filter' />";
echo "</form>";

php not following functions structure [duplicate]

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

Categories