Function error when used on another page

-2

I have the following code

class Auth {
    function getMemberByUsername($username) {
        $db_handle = new DBController();
        $query = "Select * from members where member_name = ?";
        $result = $db_handle->runQuery($query, 's', array($username));
        return $result;
    }
}

In the index I call $user = $auth->getMemberByUsername($username); and I can use the variable user normally. In the same class I also have the following fuction:

function getMemberNivel($level) {
    $db_handle = new DBController();
    $query = "Select * from members where nivel = ?";
    $result = $db_handle->runQuery($query, 'i', array($level));
    return $result;
}

and I call it as follows:

$phase = $auth->getMemberNivel($level);

    
asked by anonymous 29.12.2018 / 13:58

2 answers

0

Try to make the following change in both functions.

function getMemberByUsername($username='') {
   $db_handle = new DBController();
   $query = "Select * from members where member_name = ?";
   $result = $db_handle->runQuery($query, 's', array($username));
   return $result;
}

function getMemberNivel($level='') {
   $db_handle = new DBController();
   $query = "Select * from members where nivel = ?";
   $result = $db_handle->runQuery($query, 'i', array($level));
   return $result;
}

This will prevent the error from happening again, and do not forget to handle the return of variables. Ex.:

if(empty($username)){
   return "Username não pode ser vazio"
}
    
29.12.2018 / 14:52
-1
runQuery ($ query, 's', array ($ username));         return $ result;     }     function getTokenByUsername ($ username, $ expired) {         $ db_handle = new DBController ();         $ query="Select * from tbl_token_auth where username =? and is_expired =?";         $ result = $ db_handle-> runQuery ($ query, 'yes', array ($ username, $ expired));         return $ result;     }     function markAsExpired ($ tokenId) {         $ db_handle = new DBController ();         $ query="UPDATE tbl_token_auth SET is_expired =? WHERE id =?";         $ expired = 1;         $ result = $ db_handle-> update ($ query, 'ii', array ($ expired, $ tokenId));         return $ result;     }     function insertToken ($ username, $ random_password_hash, $ random_selector_hash, $ expiry_date) {         $ db_handle = new DBController ();         $ query="INSERT INTO tbl_token_auth (username, password_hash, selector_hash, expiry_date) values (?,?,?,?)";         $ result = $ db_handle-> insert ($ query, 'ssss', array ($ username, $ random_password_hash, $ random_selector_hash, $ expiry_date));         return $ result;     }     function getMemberLevel ($ level = '2') {         $ db_handle = new DBController ();         $ query="Select * from members where level =?";         $ result = $ db_handle-> runQuery ($ query, 'i', array ($ level));         return $ result;     }     function update ($ query) {         mysqli_query ($ this-> conn, $ query);     } } ? >     
29.12.2018 / 15:17