$InnerJoinQuery = $STD->query("
SELECT Users.ID, Users.Username, Users.Password, UserInformation.LastName, UserInformation.Firstname, UserInformation.DOB
FROM Users AS Users
INNER JOIN UserInformation AS UserInformation
ON Users.ID = UserInformation.UserID WHERE Users.Username=".$_SESSION['real_name']."");
$InnerJoinArray = $InnerJoinQuery->fetch_array(MYSQLI_ASSOC);
我上面的代码导致错误。它适用于我的WHERE
条款。
WHERE Users.Username=".$_SESSION['real_name']."
我怎样才能将这个嵌入到我的内部连接中?
更新:
$InnerJoinQuery = $STD->query("
SELECT Users.ID, Users.Username, Users.Password, UserInformation.LastName, UserInformation.Firstname, UserInformation.DOB
FROM Users
INNER JOIN UserInformation
ON Users.ID = UserInformation.UserID WHERE Users.Username = '".$_SESSION['real_name']."'");
$InnerJoinArray = $InnerJoinQuery->fetch_array(MYSQLI_ASSOC);
$_SESSION['UID'] = $InnerJoinArray['ID'];
$_SESSION['Password'] = $InnerJoinArray['Password'];
$_SESSION['Firstname'] = $InnerJoinArray['Firstname'];
$_SESSION['LastName'] = $InnerJoinArray['LastName'];
$_SESSION['DOB'] = $InnerJoinArray['DOB'];
print_r($_SESSION);
这将返回:
数组 ( [real_name] => inhumaneslayer [Password] => [UID] => [Firstname] => [LastName] => [DOB] => )
这不是预期的。
当我将查询更改为:
$InnerJoinQuery = $STD->query("
SELECT Users.ID, Users.Username, Users.Password, UserInformation.LastName, UserInformation.Firstname, UserInformation.DOB
FROM Users
INNER JOIN UserInformation
ON Users.ID = UserInformation.UserID WHERE Users.Username = 'inhumaneslayer'");
我得到了预期的结果:
数组([real_name] => inhumaneslayer [Password] => PASSWORDHIDDEN [UID] => 5 [Firstname] => xx [LastName] => xx [DOB] => DOBHIDDEN)
这是预期的。
我unset($_SESSION);
在更改 SQL 之前取消了会话