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;
}
?>





Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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 );
	}		
}

?>

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.