Call to a member function ..... ERROR :@

Status
Not open for further replies.

mehdi

New Member
Messages
1
Reaction score
0
Points
0
can anyone tell me wht shud i do:
ERROR: Fatal error: Call to a member function getRecords() on a non-object in /home/***/public_html/includes/User.php on line 166

This is my USER.php FILE:
PHP:
<?php
include_once(DOC_ROOT . 'includes/UData.php');

class User extends Main {
    
    var $con;
    
    function User()
    {
        $this->con =& parent::DB();
    }
    
    function getOne($uid)
    {
        $sql = 'SELECT *
                FROM users
                WHERE id = ' . (int) $uid;
        $this->con->getRecords($sql);
        
        return $this->con->data[0];    
    }
    
    function userExists($uname)
    {
        settype($uname, 'string');
        if (!empty($uname)) {
            
            $sql = "SELECT username
                    FROM users
                    WHERE username = '$uname'";
            $this->con->getRecords($sql, SQL_ONE); 
            
            if ($this->con->data) {
            
                return true;
            }
        }
            
        return false;    
    }
    
    function passMatch($pass1, $pass2)
    {    
        if (strcmp($pass1, $pass2) == 0) {
        
            return true;
        } else {
            
            return false;    
        }
    }
    
    function add($form_vars, $uid)
    {
         
        if (isset($uid) && (int) $uid) {

            $update = true; 
        } else {

            $update = false;
        }
        
        if ($this->userExists($form_vars['username'])) {
              $this->error[] = 'The username is already taken, please choose another';
            
            return false;
        } 
        
        if (isset($form_vars['password']) && !empty($form_vars['password'])) {
            
            if (!$this->passMatch($form_vars['password'], $form_vars['password2'])) {
            
                $this->error[] = 'The passwords do not match!';
                
                
                return false;
            } 
            $pass = $this->pw_encode($form_vars['password']);   
        } elseif ($update) {
            
            $pass = 0;    
        } else {
            
            $this->error[] = 'You must provide a password';
            
            return false;    
        }
           
         if($form_vars['has_shared_favs'] == "on"){
            $has_shared_favs = 1;
        }
        else{
            $has_shared_favs = 0;
        }
        
        if ($update) {
            
           
            $this->con->update_array = array(
                                        'firstname' => $form_vars['firstname'],
                                        'lastname'  => $form_vars['lastname'],
                                        'gender'    => $form_vars['gender'],
                                        'email'     => $form_vars['email'],
                                        'icq'       => $form_vars['icq'],
                                        'has_shared_favs'       => $has_shared_favs
                                        );
            if ($pass) {
                
                $this->con->update_array['password'] = $pass;    
            }
                                        
            $this->con->updateRecord('users', 'id = ' . (int) $uid);   
        } else {
           
            $this->con->insert_array = array(
                                        'id'         => 'NULL',
                                        'ip'         => $_SERVER['REMOTE_ADDR'],
                                        'username'   => $form_vars['username'],
                                        'firstname'  => $form_vars['firstname'],
                                        'lastname'   => $form_vars['lastname'],
                                        'gender'     => $form_vars['gender'],
                                        'email'      => $form_vars['email'],
                                        'icq'        => $form_vars['icq'],
                                        'date_added' => date('Y-m-d', time()),
                                        'has_shared_favs'       => $has_shared_favs,
                                        'password'   => $pass); 
            $this->con->addRecord('users');                                       
        }
        return true;
    }
    
    function hmac($key, $data, $hash = 'md5', $blocksize = 64) 
    {
        if (strlen($key)>$blocksize) {
            
            $key = pack('H*', $hash($key));
        }
        $key  = str_pad($key, $blocksize, chr(0));
        $ipad = str_repeat(chr(0x36), $blocksize);
        $opad = str_repeat(chr(0x5c), $blocksize);
        
        return $hash(($key^$opad) . pack('H*', $hash(($key^$ipad) . $data)));
    }

    function pw_encode($password)      
    {
        $seed = substr('00' . dechex(mt_rand()), -3) . substr('00' . dechex(mt_rand()), -3) . substr('0' . dechex(mt_rand()), -2);
        
        return $this->hmac($seed, $password, 'md5', 64) . $seed;
    }
    function pw_check($password, $stored_value) 
    {
        $seed = substr($stored_value, 32, 8);
        
        return $this->hmac($seed, $password, 'md5', 64) . $seed==$stored_value;
    }
        
    function checkLogin($user, $pass)
    {
        settype($pass, 'string');
        settype($user, 'string');
        $sql = "SELECT id as uid, username, password
                FROM users
                WHERE username = '$user'";
        $this->con->getRecords($sql);
        if ($this->con->num_records == 1) {
            
            $hash =  $this->con->data[0]['password'];  
            $valid = $this->pw_check($pass, $hash); 
            if ($valid) {
                
                $data = new UData($this->con->data[0]['uid'], $this->con->data[0]['username'], true); 
                
                return $data;
            }
        } 
            
        $data = new UData(null, null, false);
        
        return $data;    
    }
    
    /**Mariana functions*/
    
    function getLastRegUsers($limit=20){
        $sql = 'SELECT * FROM users ORDER BY firstname LIMIT '.$limit.'';
        $this->con->getRecords($sql);
                
        return $this->con->data;             
    }
    
    /**Mariana functions*/
}
?>

any IDEA?
 

Tyrael

New Member
Messages
71
Reaction score
0
Points
0
You are trying to call a function on a variable, wich isn't an object, or doesn't have that function.

Tyrael
 

zero5854

New Member
Messages
126
Reaction score
0
Points
0
umm ok im gonna need more info like what were you trying to do when u got that error...what script are u using?
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
What, getRecords() isn't a function, you need to make a function called getRecords() to use this script.
 

zero5854

New Member
Messages
126
Reaction score
0
Points
0
Actually I think that the data its trying to get form his DB simply isnt there.
 
Last edited:

lambada

New Member
Messages
2,444
Reaction score
0
Points
0
@Zero5854 The user contacted me on MSN and said it was a custom coded script. But I couldn't determine the cause of the problem with my limited understanding of OOP (Which I hope to rectify with a recode of my website).
 

Tyrael

New Member
Messages
71
Reaction score
0
Points
0
If you need help with that, I can check it for you.

Tyrael
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Closing this since the thread creator has not responded.

-Corey
 
Status
Not open for further replies.
Top