如何解决尝试访问php中bool类型值的数组偏移量
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']
作为数组,没有结果验证。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。