Having trouble with functions structure not following (PHP)
<pre><code>&lt;?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();
                }

            }

        }



    ?&gt;
</code></pre>

<p>I am trying to follow a page structure which goes like this:</p>

<ul>
<li><p><code>PickModule()</code> is displayed</p></li>
<li><p>When user submits in <code>PickModule()</code> function, it will do a check in <code>if(ModuleIsSubmitted())</code> and then output results of check in <code>PickSession()</code></p></li>
<li><p><code>PickSession()</code> is displayed</p></li>
<li><p>When user submits in <code>PickSession()</code> function, it will do a check in <code>if(SessionIsSubmitted())</code> and then output results of check in <code>ShowAssessment()</code></p></li>
<li><p><code>ShowAssessment()</code> is displayed</p></li>
<li><p>When user submits in <code>ShowAssessment()</code> function, it will do a check in <code>if(StudentAnswersIsSubmitted())</code> to check that submit button was clicked and then output results in <code>StudentAnswers()</code></p></li>
<li><p><code>StudentAnswers()</code> is displayed</p></li>
</ul>

<p>The problem I have is with the last two bullet points, when the <code>answerSubmit</code> button is clicked and is checked upon in <code>if(StudentAnswersIsSubmitted())</code>, then instead of displaying results in <code>StudentAnswers()</code>, it goes straight back up to the <code>PickModule()</code> function. What am I doing wrong?</p>

<p>Below is the code where it goes trough each function:</p>

<p>HERE IS DEMO FOR CODE BELOW: <a href="http://helios.hud.ac.uk/u0867587/Mobile_app/Text29.php" rel="nofollow">DEMO</a></p>

<pre><code>function PickModule()
{ ?&gt;
    &lt;form action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post"&gt; 
        &lt;?php            
        $moduleactive = 1;

        $sql = "SELECT ModuleId, ModuleNo, ModuleName FROM Module WHERE ModuleActive = ? ORDER BY ModuleNo"; 

        //mysqli code for modules drop down menu

        ?&gt;
        &lt;strong&gt;Module:&lt;/strong&gt;
        &lt;select name="module" id="modulesDrop"&gt;
            &lt;option value=""&gt;Please Select&lt;/option&gt;
            &lt;?php
            while($sqlstmt-&gt;fetch()) { 
                $ov = $dbModuleNo . "_" . $dbModuleName . "_" . $dbModuleId; 
                if(isset($_POST["module"]) &amp;&amp; $ov == $_POST["module"]) 
                    echo "&lt;option selected='selected' value='$ov'&gt;$dbModuleNo - $dbModuleName&lt;/option&gt;" . PHP_EOL; 
                else 
                    echo "&lt;option value='$ov'&gt;$dbModuleNo - $dbModuleName&lt;/option&gt;" . PHP_EOL;
             } 
            ?&gt;
        &lt;/select&gt;
        &lt;br&gt;
        &lt;input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" /&gt;
    &lt;/form&gt;
&lt;?php }
function ModuleIsSubmitted()
{
    if(isset($_POST["module"]) &amp;&amp; empty($_POST["module"])) // We picked the "Please select" option
    { ?&gt;
            Please Select a Module
    &lt;?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  

    ?&gt;

    &lt;form action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post"&gt; 
        &lt;input type="hidden" name="module" value="&lt;?php echo $_POST['module']; ?&gt;"&gt;
        &lt;p&gt;
            &lt;strong&gt;Selected Module: &lt;/strong&gt;&lt;?php echo $moduleNo ." - ". $moduleName; ?&gt; 
        &lt;/p&gt;
    &lt;?php if ($sessionnum == 0 ){ ?&gt;
        &lt;div class="red"&gt;
            Sorry, You have No Assessments under this Module
        &lt;/div&gt;
    &lt;?php } else { ?&gt;
           &lt;p&gt;
        &lt;strong&gt;Asessments:&lt;/strong&gt;
        &lt;select name="session" id="sessionsDrop"&gt;
            &lt;option value=""&gt;Please Select&lt;/option&gt;
            &lt;?php
                while ( $sessionqrystmt-&gt;fetch() ) {
                    $sv = $dbSessionId;
                    if($dbSessionActive == 0){
                        $class = 'red';
                    }else{
                        $class = 'green';   
                    }
                    if(isset($_POST["session"]) &amp;&amp; $sv == $_POST["session"]) 
                        echo "&lt;option selected='selected' value='$sv' class='$class'&gt;" . $dbSessionName . " - " . date('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "&lt;/option&gt;" . PHP_EOL;
                    else
                        echo "&lt;option value='$sv' class='$class'&gt;" . $dbSessionName . " - " . date('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "&lt;/option&gt;" . PHP_EOL;
                }
            ?&gt;
        &lt;/select&gt;
        &lt;/p&gt;
        &lt;input id="sessionSubmit" type="submit" value="Submit Assessments" name="sessionSubmit" /&gt;
    &lt;/form&gt;
&lt;?php
}
}
function SessionIsSubmitted()
{
        if(isset($_POST["session"]) &amp;&amp; empty($_POST["session"])) // We picked the "Please select" option
        { ?&gt;
            &lt;div class="red"&gt;
                Please Select an Assessment
            &lt;/div&gt;
        &lt;?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){ ?&gt;

&lt;div class="red"&gt;
There are no Students who have currently taken this Assessment
&lt;/div&gt;
&lt;?php } else { 

$questionsqry = "
SELECT
QuestionId, QuestionNo
FROM
Question
WHERE
(SessionId = ?)
ORDER BY QuestionNo
";

//mysqli code for questions drop down menu

        ?&gt;

&lt;form action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post"&gt;         
&lt;p&gt;
&lt;input type="text" name="session" value="&lt;?php echo $_POST['session']; ?&gt;"&gt;
&lt;strong&gt;Student:&lt;/strong&gt;
&lt;select name="student" id="studentsDrop"&gt;
&lt;option value="All"&gt;All&lt;/option&gt;
&lt;?php
while ( $currentstudentstmt-&gt;fetch() ) {
$stu = $dbStudentId;
if(isset($_POST["student"]) &amp;&amp; $stu == $_POST["student"]) 
    echo "&lt;option selected='selected' value='$stu'&gt;" . $dbStudentAlias . " - " . $dbStudentForename . " " . $dbStudentSurname . "&lt;/option&gt;" . PHP_EOL;
else
    echo "&lt;option value='$stu'&gt;" . $dbStudentAlias . " - " . $dbStudentForename . " " . $dbStudentSurname . "&lt;/option&gt;" . PHP_EOL;
}
?&gt;
&lt;/select&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Question:&lt;/strong&gt;
&lt;select name="question" id="questionsDrop"&gt;
&lt;option value="All"&gt;All&lt;/option&gt;
&lt;?php
while ( $questionsstmt-&gt;fetch() ) {
$ques = $dbQuestionId;
if(isset($_POST["question"]) &amp;&amp; $ques == $_POST["question"]) 
    echo "&lt;option selected='selected' value='$ques'&gt;" . $dbQuestionNo . "&lt;/option&gt;" . PHP_EOL;
else
    echo "&lt;option value='$ques'&gt;" . $dbQuestionNo . "&lt;/option&gt;" . PHP_EOL;
}
?&gt;
&lt;/select&gt;
&lt;/p&gt;

&lt;input id="answerSubmit" type="submit" value="Get Student's Answers" name="answerSubmit" /&gt;
&lt;/form&gt;

&lt;?php
}
}

function StudentAnswersIsSubmitted()
{

if(!isset($_POST["answerSubmit"]))
    {
        return false;
    }
    else // All is ok
    {
        return true;
    }
    return false;

}

function StudentAnswers()
{

echo "student answers";

}

?&gt;
</code></pre>
