How to display the correct data in their respective text inputs?
<p>I am having trouble displaying the SessionName, SessionDate and SessionTime in their respective text inputs. What should happen is that the user is suppose to select a Session (Assessment) from the drop down menu. Now when they submit the drop down menu, the details of the Session which are SessionName, SessionDate and SessionTime, should be displayed in their text inputs. But instead I am recieving undefined variable errors which are these below:</p>

<blockquote>
  <p>Notice: Undefined variable: dbSessionName in ...on line 243</p>
  
  <p>Notice: Undefined variable: dbSessionDate in ... on line 244</p>
  
  <p>Notice: Undefined variable: dbSessionTime in ... on line 245</p>
</blockquote>

<p>How can I get the SessionName, SessionTime and SessionDate to be displayed in their respective text inputs?</p>

<p>Below is the code:</p>

<pre><code>$sessionquery = "
SELECT SessionId, SessionName, SessionDate, SessionTime, ModuleId
FROM Session
WHERE
(ModuleId = ?)
ORDER BY SessionDate, SessionTime 
";

$sessionqrystmt=$mysqli-&gt;prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt-&gt;bind_param("s",$_POST['modules']);
// get result and assign variables (prefix with db)

$sessionqrystmt-&gt;execute(); 

$sessionqrystmt-&gt;bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId);

$sessionqrystmt-&gt;store_result();

$sessionnum = $sessionqrystmt-&gt;num_rows();   

if($sessionnum ==0){
echo "&lt;p&gt;Sorry, You have No Assessments under this Module&lt;/p&gt;";
} else { 

$sessionHTML = '&lt;select name="session" id="sessionsDrop"&gt;'.PHP_EOL;
$sessionHTML .= '&lt;option value=""&gt;Please Select&lt;/option&gt;'.PHP_EOL;           

while ( $sessionqrystmt-&gt;fetch() ) {
    $sessionHTML .= sprintf("&lt;option value='%s'&gt;%s - %s - %s&lt;/option&gt;", $dbSessionId, $dbSessionName, $dbSessionDate, $dbSessionTime) . PHP_EOL;  
}

$sessionHTML .= '&lt;/select&gt;';

$assessmentform = "&lt;form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' onsubmit='return sessionvalidation();'&gt;
&lt;p&gt;Assessments: {$sessionHTML} &lt;/p&gt;
&lt;p&gt;&lt;input id='sessionSubmit' type='submit' value='Submit Assessment' name='sessionSubmit' /&gt;&lt;/p&gt;  
&lt;div id='sessionAlert'&gt;&lt;/div&gt;    
&lt;/form&gt;";

echo $assessmentform;

}

}

if (isset($_POST['sessionSubmit'])) {   

$currentsession = "form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post'&gt;
&lt;p&gt;Current Assessment's Date/Start Time:&lt;/p&gt;
&lt;p&gt;Assessment: &lt;input type='text' id='currentAssessment' name='Assessmentcurrent' readonly='readonly' value='{$dbSessionName}'/&gt; &lt;/p&gt; //Line 243
&lt;p&gt;Date: &lt;input type='text' id='currentDate' name='Datecurrent' readonly='readonly' value='{$dbSessionDate}'/&gt; &lt;/p&gt; //Line 244
&lt;p&gt;Start Time: &lt;input type='text' id='currentTime' name='Timecurrent' readonly='readonly' value='{$dbSessionTime}'/&gt; &lt;/p&gt; //Line 245
&lt;/form&gt;
";  

echo $currentsession;

    }
</code></pre>

<p><strong>UPDATE:</strong></p>

<p>Could the code below do it:</p>

<pre><code>if (isset($_POST['sessionSubmit'])) {

    $sessionquery = "
    SELECT SessionId, SessionName, SessionDate, SessionTime, ModuleId
    FROM Session
    WHERE
    (ModuleId = ?)
    ORDER BY SessionDate, SessionTime 
    ";

    $sessionqrystmt=$mysqli-&gt;prepare($sessionquery);
    // You only need to call bind_param once
    $sessionqrystmt-&gt;bind_param("s",$_POST['modules']);
    // get result and assign variables (prefix with db)

    $sessionqrystmt-&gt;execute(); 

    $sessionqrystmt-&gt;bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId);

    $sessionqrystmt-&gt;store_result();

$currentsession = "&lt;form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post'&gt;
&lt;p&gt;Current Assessment's Date/Start Time:&lt;/p&gt;
&lt;p&gt;Assessment: &lt;input type='text' id='currentAssessment' name='Assessmentcurrent' readonly='readonly' value='{$dbSessionName}'/&gt; &lt;/p&gt;
&lt;p&gt;Date: &lt;input type='text' id='currentDate' name='Datecurrent' readonly='readonly' value='{$dbSessionDate}'/&gt; &lt;/p&gt;
&lt;p&gt;Start Time: &lt;input type='text' id='currentTime' name='Timecurrent' readonly='readonly' value='{$dbSessionTime}'/&gt; &lt;/p&gt;
&lt;input type='hidden' id='hiddenId' name='hiddenAssessment' value='{$dbSessionId}'/&gt;
&lt;/form&gt;
";  

echo $currentsession;

    }
</code></pre>

<p>Do I need the store_result(); in this situation?</p>
