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;
}
I tried to solve it but I can't.
Notice: Trying to access array offset on value of type bool in C:\xampp\htdocs\admin\core\classes\user.Class.php on line 128
Notice: Trying to access array offset on value of type bool in C:\xampp\htdocs\admin\core\classes\user.Class.php on line 133
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).....then it will work normally
$infois returningtrueorfalse, why dont youvar_dump($info)to see whats happening?stripslashes()has absolutely no business being in this code, andhtmlspecialchars()is only for HTML escaping when displaying. Do not use it for SQL escaping. You're (correctly) using placeholder values which means this code is completely pointless.execute()succeeded. It may have failed. Tip: Turn on exceptions with$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);$info['active'], your SQL query already selectactive=$active?