0

I seem to have an error I don't really understand. The process works fine, the connection to database is fine, but for some reason it doesn't update. There are no visible errors for me, or that php recognizes. Here is the code: (note that the last missing) on class I know about, and that happened when I copy pasted it, it's fine in the code

    public function change_password($user, $pass) {
    if($user) {
        $password = md5($pass);
        $this->_query = $this->_pdo->prepare("UPDATE users SET password = ? WHERE ? = ?");
        if($this->_query->execute(array($pass, Check::data($user), $user))) {
            return true;
        }
    }
    return false;
}



class Check {
public static function data($data) {
    if($data) {
        if(is_numeric($data)) {
            $_id = 'id';
        } else if(filter_var($data, FILTER_VALIDATE_EMAIL)) {
            $_id = 'email';
        } else {
            $_id = 'username';
        }
        return $_id;
    }
    return false;
} 

}

Phil
  • 157,677
  • 23
  • 242
  • 245

1 Answers1

0

If anyone is intressed, I resolved the problem, and for future simular problems , I found a way around..

    public function change_password($user, $pass) {
    if($user) {
        $pass = md5($pass);
        $id = $this->id($user);

        $this->_query = $this->_pdo->prepare("UPDATE users SET password = ? WHERE id = ?");
        if($this->_query->execute(array($pass, $id))) {
            return true;
        }
    }
    return false;
}


    public function id($user) {
    if($user) {
        $params = $this->fetch($user);

        foreach($params as $param) {
            if($param['id']) {
                return $param['id'];
            }
        }
    }
    return false;
}

    public function fetch($user) {
    if($user) {
        if(Check::data($user) === 'id') {
            $this->_query = $this->_pdo->prepare("SELECT * FROM users WHERE id = :user");
        }

        if(Check::data($user) === 'email') {
            $this->_query = $this->_pdo->prepare("SELECT * FROM users WHERE email = :user");
        }

        if(Check::data($user) === 'username') {
            $this->_query = $this->_pdo->prepare("SELECT * FROM users WHERE username = :user");
        }

        $this->_query->execute(array(':user' => $user));
        return $this->_query->fetchAll();           
    }
    return false;
}`class Check {
public static function data($data) {
    if($data) {
        if(is_numeric($data)) {
            $_id = 'id';
        } else if(filter_var($data, FILTER_VALIDATE_EMAIL)) {
            $_id = 'email';
        } else {
            $_id = 'username';
        }
        return $_id;
    }
    return false;
} }