问题描述
function Checkactive($active){
$db = new Connect;
$result = '';
if(isset($active)){
if(empty($active)){
}else{
$active = stripslashes(htmlspecialchars($active));
$user = $db -> prepare("SELECT * FROM users WHERE active = :active");
$user->execute(array(
'active' => $active
));
$info = $user->fetch(PDO::FETCH_ASSOC);
if($info['active'] != 'active'){ //line 128
$hash = $this->generateCode(10);
$upd = $db->prepare("UPDATE users SET active=:hash WHERE id=:ex_user");
$upd -> execute(array(
'hash' => $hash,'ex_user' => $info['id'] //line 133
));
echo "sucess";
}else {
echo "failer";
}
}
}
return $result;
}
我试图解决它,但我不能。
注意:尝试访问第 128 行 C:\xampp\htdocs\admin\core\classes\user.Class.PHP 中 bool 类型值的数组偏移
注意:尝试访问第 133 行 C:\xampp\htdocs\admin\core\classes\user.Class.PHP 中 bool 类型值的数组偏移量
function Checkactive($active){
$db = new Connect;
echo "first";
$result = '';
if(isset($active)){
if(empty($active)){
}else{
echo $active;
$active = stripslashes(htmlspecialchars($active));
$user = $db -> prepare("SELECT * FROM users WHERE actived = :active");
$user->execute(array('active' => $active)); //remove array('active' => $active).....then it will work normally
$info = $user->fetch(PDO::FETCH_ASSOC);
var_dump($info); // still return bool(false)
// if( $info['actived'] == 'active'){
// $hash = $active;
// $upd = $db->prepare("UPDATE users SET actived = :hash WHERE id = :ex_user");
// $upd -> execute(array(
// 'hash' => $hash,// 'ex_user' => $info["id"]
// ));
// echo "sucess";
// }else {
// $hash = "two";
// var_dump($active);
// $upd = $db->prepare("UPDATE users SET actived = :hash WHERE id = :ex_user");
// $upd -> execute(array(
// 'hash' => $hash,// 'ex_user' => $info["id"]
// ));
// var_dump($info);
// var_dump($active);
// echo "failer";
// }
}
}
remove array('active' => $active).....就可以正常工作了
解决方法
您在 $user->fetch(PDO::FETCH_ASSOC)
中有错误,因此它返回 FALSE,而不是数组。
之后,您使用 $info['active']
和 $info['id']
作为数组,没有结果验证。