在我下面的代码中,它无法识别该变量$userid
,该变量确定了登录教师的 ID,但在 mysqli 代码中,它无法确定$userid
我何时回显它。但它确实知道用户是通过它的$userid
. 所以我的问题是,在 mysqli 为什么找不到$userid
?请查看 mysqli 设置中的评论bind_param()
,这就是问题所在。
以下是php和mysqli的代码:
让我声明 member.php 是包含以下$userid
信息的脚本:
<?php
session_start();
include('member.php');
...
function PickSession()
{
//Get data from database
$sessionquery = "
SELECT s.SessionId, SessionName, s.TeacherId
FROM Session s
INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId
WHERE
(ModuleId = ? AND Complete = ? AND s.TeacherId = ?)
ORDER BY SessionName
";
$complete = 1;
global $mysqli;
$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("iii",$moduleId, $complete, $userid);//it doesn't recognse $userid
// get result and assign variables (prefix with db)
$sessionqrystmt->execute();
$sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbTeacherId);
$sessionqrystmt->store_result();
$sessionnum = $sessionqrystmt->num_rows();
echo $userid; //nothing displayed in this echo
...
if ((isset($username)) && (isset($userid))){ //user is successfully logged in
include('teachername.php');
...
<?php
ShowAssessment(); // Show information
}else{
echo "Please Login to Access this Page | <a href='./teacherlogin.php'>Login</a>";
}
?>
member.php 脚本:
if (isset($_SESSION['teacherid'])) {
$userid = $_SESSION['teacherid'];
}
if (isset($_SESSION['teacherusername'])) {
$username = $_SESSION['teacherusername'];
}
?>