外键不等于主键
foreign key is not equal to primary key
所以我的查询看起来像这样
`$dbUser = "SELECT * FROM accaount, role WHERE Username = :username AND Password = :password UNION SELECT * FROM role , accaount WHERE Role_idRole = idRole ";
$query = $conn->prepare( $dbUser);
$query->bindParam(":username", $Username);
$query->bindParam(":password", $Password);
$query->execute();`
错误是UNION SELECT * FROM role , accaount WHERE Role_idRole = idRole.
我试图做的是使我的外键(Role_idRole)等于我的主键来自另一个table称为角色的主键身份角色。我尝试做的是查看您的帐户是否是管理员帐户。因此,如果我是管理员,则 Name = 1 而不是 Name = 0。名称在角色 table 中。
这是我的完整登录代码
`<?php
if(!isset($_SESSION))
{
session_start();
}
require('dbConnection.php');
$Password = $_POST['LPassword'];
$Username = $_POST['LUsername'];
$dbUser = "SELECT * FROM accaount, role WHERE Username = :username AND Password = :password UNION SELECT * FROM role , accaount WHERE Role_idRole = idRole ";
$query = $conn->prepare( $dbUser);
$query->bindParam(":username", $Username);
$query->bindParam(":password", $Password);
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);
var_dump($result);
if ($result["Username"] == $Username && $result["Password"] == $Password) {
if($result['Name'] == 0) {
$_SESSION['LOGINUsername'] = $Username;
echo "Member";
}
$tpl->assign('USERNAME', $Username);
if($result['Name'] == 1) {
$_SESSION['LOGINAdmin'] = $Username;
echo "Admin";
}
}
else {
echo "FAIL!";
}`
我知道帐户拼写错误,但这不是错误,它在我的数据库中也是如此。这也是 var dump 显示的内容
数组(大小=8)
'idAccaount' => 整数 2
'Username' => 字符串 'rwere' (长度=5)
'Password' => 字符串 'rwere' (长度=5)
'salt' => 字符串 '380' (长度=3)
'Reset' => 空
'Role_idRole' => 字符串 '45' (长度=2)
'idRole' => 字符串 '40' (长度=2)
'Name' => 整数 1
如您所见,此人必须是会员而不是管理员。如果我们查看 idRole 45,名称 int 必须为 0。
我真的很迷茫
$dbUser = "SELECT accaount.Username, accaount.Password, accaount.Role_idRole, role.Name FROM accaount INNER JOIN role ON accaount.Role_idRole=role.idRole WHERE accaount.Username = :username AND accaount.Password = :password AND Role_idRole = idRole";
所以我的查询看起来像这样
`$dbUser = "SELECT * FROM accaount, role WHERE Username = :username AND Password = :password UNION SELECT * FROM role , accaount WHERE Role_idRole = idRole ";
$query = $conn->prepare( $dbUser);
$query->bindParam(":username", $Username);
$query->bindParam(":password", $Password);
$query->execute();`
错误是UNION SELECT * FROM role , accaount WHERE Role_idRole = idRole.
我试图做的是使我的外键(Role_idRole)等于我的主键来自另一个table称为角色的主键身份角色。我尝试做的是查看您的帐户是否是管理员帐户。因此,如果我是管理员,则 Name = 1 而不是 Name = 0。名称在角色 table 中。
这是我的完整登录代码
`<?php
if(!isset($_SESSION))
{
session_start();
}
require('dbConnection.php');
$Password = $_POST['LPassword'];
$Username = $_POST['LUsername'];
$dbUser = "SELECT * FROM accaount, role WHERE Username = :username AND Password = :password UNION SELECT * FROM role , accaount WHERE Role_idRole = idRole ";
$query = $conn->prepare( $dbUser);
$query->bindParam(":username", $Username);
$query->bindParam(":password", $Password);
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);
var_dump($result);
if ($result["Username"] == $Username && $result["Password"] == $Password) {
if($result['Name'] == 0) {
$_SESSION['LOGINUsername'] = $Username;
echo "Member";
}
$tpl->assign('USERNAME', $Username);
if($result['Name'] == 1) {
$_SESSION['LOGINAdmin'] = $Username;
echo "Admin";
}
}
else {
echo "FAIL!";
}`
我知道帐户拼写错误,但这不是错误,它在我的数据库中也是如此。这也是 var dump 显示的内容
数组(大小=8)
'idAccaount' => 整数 2
'Username' => 字符串 'rwere' (长度=5)
'Password' => 字符串 'rwere' (长度=5)
'salt' => 字符串 '380' (长度=3)
'Reset' => 空
'Role_idRole' => 字符串 '45' (长度=2)
'idRole' => 字符串 '40' (长度=2)
'Name' => 整数 1
如您所见,此人必须是会员而不是管理员。如果我们查看 idRole 45,名称 int 必须为 0。
我真的很迷茫
$dbUser = "SELECT accaount.Username, accaount.Password, accaount.Role_idRole, role.Name FROM accaount INNER JOIN role ON accaount.Role_idRole=role.idRole WHERE accaount.Username = :username AND accaount.Password = :password AND Role_idRole = idRole";