TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Doh! (http://www.talkphp.com/general/4146-doh.html)

Sam Granger 04-16-2009 09:16 PM

Doh!
 
Fatal error: Call to a member function executeQuery() on a non-object in /home/phpsauce/public_html/sources/authClass.php on line 65

PHP Code:

    function checkSession() {
        @
session_start();
        
$username $_SESSION['username'];
         
$session session_id();
        
$ip $_SERVER['REMOTE_ADDR'];
        
$query "SELECT * FROM users WHERE (username = '$username') AND (session = '$session') AND (ip = '$ip')";
        
$result $connect->executeQuery($query) or die('Auth Subsystem Error');

        if (
mysqli_num_rows($result) > ) {
            return 
true;
        } else {
            
$this->session_defaults();
            return 
false;
        }
    } 

Line 65:
PHP Code:

$result $connect->executeQuery($query) or die('Auth Subsystem Error'); 

What am I doing wrong? :-/

Sam Granger 04-16-2009 09:19 PM

And if it helps, here is the executeQuery code:

PHP Code:

    public function executeQuery($query) {
        if(
$res mysqli_query($this->link,$query)) {
            return 
$res;
        }
        else {
            
$this->dbError mysqli_error($this->link);
            return 
false;
        }
    } 


Salathe 04-16-2009 09:19 PM

The variable $connect (local to the scope of that function) is not defined and undefined variables don't have methods attached. Which class has an executeQuery method and where is it instantiated?

Edit: Are these both defined in the same class?

Sam Granger 04-16-2009 09:27 PM

Thanks for your fast reply :)

PHP Code:

    function __construct() {
        @
session_start();
        require_once( 
SOURCES_PATH 'dbClass.php' );
        
$connect = new dbClass();
        
$connect->dbConnect'localhost''user''pass''database' );

        @
session_start();

        if (!isset(
$_SESSION['logged'])) {
            
$this->session_defaults();  
        }

    } 

This is from the authClass. dbClass contains the executeQuery function.

Salathe 04-16-2009 10:33 PM

The $connect variable is only available within the __construct. The simplest workaround would be to use $this->connect wherever you have just $connect right now.

Sam Granger 04-16-2009 10:44 PM

Quote:

Originally Posted by Salathe (Post 23129)
The $connect variable is only available within the __construct. The simplest workaround would be to use $this->connect wherever you have just $connect right now.

Ah! Starting to understand OOP a bit better now, thanks Salathe! ^^


All times are GMT. The time now is 06:25 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0