在那里我创建了这个函数,如果有用户名那么在表中找到密码!
但是我收到了这个错误:
protected function checkLogin()
{
$conn = $this->connectDB();
$password = mysqli_real_escape_string($conn, trim($_SESSION["password"]));
$username = mysqli_real_escape_string($conn, trim($_SESSION["username"]));
$conn = $this->connectDB();
$record = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM profile WHERE email = '".$username."' OR cellphone = '".$username."' OR username = '".$username."'"));
if ($conn->error)
{
echo $conn->error;
$conn->close();
return false;
}
$record = $record['password'];
$conn->close();
if($this->matchPasswords($record['password']))
return true;
return false;
}
错误:
(!)警告:非法字符串偏移'密码'在 第383行的F:\ wamp \ www \ myweb \ libs \ core.php
我错了什么?
答案 0 :(得分:3)
$record = $record['password'];
$conn->close();
if($this->matchPasswords($record['password']))
最有可能$record
现在是一个字符串,但不是一个数组。
答案 1 :(得分:1)
> $record = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM
> profile WHERE email = '".$username."' OR cellphone = '".$username."'
> OR username = '".$username."'"));
返回一个关联表,为什么要执行此操作$record = $record['password'];
?
尝试通过函数print_r
显示内容