nikes Posted March 11, 2009 Share Posted March 11, 2009 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; } ?> Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 11, 2009 Share Posted March 11, 2009 Which line exactly is line 76? Check if $db is instantiated when this function is called. Quote Link to comment Share on other sites More sharing options...
nikes Posted March 11, 2009 Author Share Posted March 11, 2009 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. Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 11, 2009 Share Posted March 11, 2009 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. Quote Link to comment Share on other sites More sharing options...
nikes Posted March 11, 2009 Author Share Posted March 11, 2009 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? Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 11, 2009 Share Posted March 11, 2009 For start do this right after global $db; Quote Link to comment Share on other sites More sharing options...
nikes Posted March 11, 2009 Author Share Posted March 11, 2009 For start do this right after global $db; ok it says: NULL Fatal error: Call to a member function on a non-object in functions.php on line 77. Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 11, 2009 Share Posted March 11, 2009 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. Quote Link to comment Share on other sites More sharing options...
nikes Posted March 11, 2009 Author Share Posted March 11, 2009 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 ); } } ?> Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 11, 2009 Share Posted March 11, 2009 Yeah. Quote Link to comment Share on other sites More sharing options...
nikes Posted March 11, 2009 Author Share Posted March 11, 2009 Yeah. i'm still getting the NULL NULL fatal error. What am i doing wrong? Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 11, 2009 Share Posted March 11, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.