我无法在各自的文本输入中显示 SessionName、SessionDate 和 SessionTime。应该发生的是用户应该从下拉菜单中选择一个会话(评估)。现在,当他们提交下拉菜单时,应在其文本输入中显示 Session 的详细信息,即 SessionName、SessionDate 和 SessionTime。但相反,我收到未定义的变量错误,这些错误如下:
注意:未定义的变量:dbSessionName in ...第 243 行
注意:未定义的变量:dbSessionDate in ... 第 244 行
注意:未定义的变量:dbSessionTime in ... 第 245 行
如何让 SessionName、SessionTime 和 SessionDate 显示在它们各自的文本输入中?
下面是代码:
$sessionquery = "
SELECT SessionId, SessionName, SessionDate, SessionTime, ModuleId
FROM Session
WHERE
(ModuleId = ?)
ORDER BY SessionDate, SessionTime
";
$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("s",$_POST['modules']);
// get result and assign variables (prefix with db)
$sessionqrystmt->execute();
$sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId);
$sessionqrystmt->store_result();
$sessionnum = $sessionqrystmt->num_rows();
if($sessionnum ==0){
echo "<p>Sorry, You have No Assessments under this Module</p>";
} else {
$sessionHTML = '<select name="session" id="sessionsDrop">'.PHP_EOL;
$sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;
while ( $sessionqrystmt->fetch() ) {
$sessionHTML .= sprintf("<option value='%s'>%s - %s - %s</option>", $dbSessionId, $dbSessionName, $dbSessionDate, $dbSessionTime) . PHP_EOL;
}
$sessionHTML .= '</select>';
$assessmentform = "<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' onsubmit='return sessionvalidation();'>
<p>Assessments: {$sessionHTML} </p>
<p><input id='sessionSubmit' type='submit' value='Submit Assessment' name='sessionSubmit' /></p>
<div id='sessionAlert'></div>
</form>";
echo $assessmentform;
}
}
if (isset($_POST['sessionSubmit'])) {
$currentsession = "form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post'>
<p>Current Assessment's Date/Start Time:</p>
<p>Assessment: <input type='text' id='currentAssessment' name='Assessmentcurrent' readonly='readonly' value='{$dbSessionName}'/> </p> //Line 243
<p>Date: <input type='text' id='currentDate' name='Datecurrent' readonly='readonly' value='{$dbSessionDate}'/> </p> //Line 244
<p>Start Time: <input type='text' id='currentTime' name='Timecurrent' readonly='readonly' value='{$dbSessionTime}'/> </p> //Line 245
</form>
";
echo $currentsession;
}
更新:
下面的代码可以做到吗:
if (isset($_POST['sessionSubmit'])) {
$sessionquery = "
SELECT SessionId, SessionName, SessionDate, SessionTime, ModuleId
FROM Session
WHERE
(ModuleId = ?)
ORDER BY SessionDate, SessionTime
";
$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("s",$_POST['modules']);
// get result and assign variables (prefix with db)
$sessionqrystmt->execute();
$sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId);
$sessionqrystmt->store_result();
$currentsession = "<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post'>
<p>Current Assessment's Date/Start Time:</p>
<p>Assessment: <input type='text' id='currentAssessment' name='Assessmentcurrent' readonly='readonly' value='{$dbSessionName}'/> </p>
<p>Date: <input type='text' id='currentDate' name='Datecurrent' readonly='readonly' value='{$dbSessionDate}'/> </p>
<p>Start Time: <input type='text' id='currentTime' name='Timecurrent' readonly='readonly' value='{$dbSessionTime}'/> </p>
<input type='hidden' id='hiddenId' name='hiddenAssessment' value='{$dbSessionId}'/>
</form>
";
echo $currentsession;
}
我需要 store_result(); 在这个情况下?