Question

I am building a membership system in php using sessions, functions and MySQL querys, I have come across a problem or a error that I do not understand the meaning and how to correct it. any help on this matter would be greatly appreciated.

Error reads

Fatal error: Call to a member function error() on a non-object in /home/ob219/public_html/membership/index.php on line 6

code for index

$user = DB::getInstance()->get('users', array('username', '=', 'ben'));

if($user->error()) {
    echo 'No user';
} else {
    echo 'OK!';
}

db.php function

public function action($action, $table, $where = array()) {
    if(count($where) === 3) {
        $operators = array('=', '>', '<', '>=', '<=');

        $field       = $where[0];
        $operator    = $where[1];
        $value       = $where[2];

        if(in_array($operator, $operators)) {
            $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";

            if(!$this->query($sql, array($value))->error()) {
                return $this;
            }
        }
    }
    return false;
}

public function get($table, $where) {
    return $this->action('SELECT *', $table, $where);
}

public function delete($table, $where) {
    return $this->action('DELETE', $table, $where);

}

public function error() {
    return $this->_error;
}
Was it helpful?

Solution

was a simple error, I had Users as table name, and in index.php I had users.

Solution

    <?php
require_once 'core/init.php';
$user = DB::getInstance()->get('Users', array('username', '=', 'ben'));
if((!$user->count())) {
    echo 'No user';
} else {
    echo 'OK!';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top