Jump to content

Fatal error: Call to a member function on a non-object in functions.php.......


nikes

Recommended Posts

Fatal error: Call to a member function on a non-object in functions.php on line 76..

 

this is the part that has the line error:

 

<?php
function get_level_access ( $user_id )
{
	global $db;
$row = $db->getRow ( 'SELECT Level_access FROM ' . DBPREFIX . 'users WHERE ID  = ' . $db->qstr ( $user_id ) );
return $row->Level_access;
}
?>





Which line exactly is line 76?

 

Check if $db is instantiated when this function is called.

 

this is line 76:

 

$row = $db->getRow ( 'SELECT Level_access FROM ' . DBPREFIX . 'users WHERE ID = ' . $db->qstr ( $user_id ) );

 

and how do i check if $db is instantiated when this function is called.

As I said. You should make sure, that $db is the database object, when this function is called.

 

and how do i check if $db is instantiated when this function is called.

 

Do var_dump($db) and see what it echoes.

As I said. You should make sure, that $db is the database object, when this function is called.

 

and how do i check if $db is instantiated when this function is called.

 

Do var_dump($db) and see what it echoes.

 

:-\Sorry I'm a beginner at this........ where do i do this at?

So we know now, $db is not an object, when it should be. Now you have to find where get_level_access() function is called in your code. In each of these places, you should check if $db is instantiated.

 

So we know now, $db is not an object, when it should be. Now you have to find where get_level_access() function is called in your code. In each of these places, you should check if $db is instantiated.

ok for example (this is the other part of the functions.php file ) i put var_dump($db) after global $db right?

 

<?php
function checkLogin ( $levels )
{
	session_start ();
	global $db;
	$kt = split ( ' ', $levels );

	if ( ! $_SESSION['logged_in'] ) {

		$access = FALSE;

		if ( isset ( $_COOKIE['cookie_id'] ) ) {//if we have a cookie

			$query =  'SELECT * FROM ' . DBPREFIX . 'users WHERE ID = ' . $db->qstr ( $_COOKIE['cookie_id'] );

			if ( $db->RecordCount ( $query ) == 1 ) {//only one user can match that query
				$row = $db->getRow ( $query );

				//let's see if we pass the validation, no monkey business
				if ( $_COOKIE['authenticate'] == md5 ( getIP () . $row->Password . $_SERVER['USER_AGENT'] ) ) {
					//we set the sessions so we don't repeat this step over and over again
					$_SESSION['user_id'] = $row->ID;				
					$_SESSION['logged_in'] = TRUE;

					//now we check the level access, we might not have the permission
					if ( in_array ( get_level_access ( $_SESSION['user_id'] ), $kt ) ) {
						//we do?! horray!
						$access = TRUE;
					}
				}
			}
		}
	}
	else {			
		$access = FALSE;

		if ( in_array ( get_level_access ( $_SESSION['user_id'] ), $kt ) ) {
			$access = TRUE;
		}
	}

	if ( $access == FALSE ) {
		header ( "Location: " . REDIRECT_TO_LOGIN );
	}		
}

?>

It still is not instantiated. You just have to go higher and higher until you reach top level script. Then you can check, if/why $db is not instantiated.

 

BTW: You may remove var_dump() lines, after you no longer need them ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.