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; } ?> Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/ 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. Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782111 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. Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782115 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. Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782116 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? Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782121 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; Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782122 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. Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782124 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. Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782130 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 ); } } ?> Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782142 Share on other sites More sharing options...
Mchl Posted March 11, 2009 Share Posted March 11, 2009 Yeah. Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782169 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? Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782198 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 Link to comment https://forums.phpfreaks.com/topic/148954-fatal-error-call-to-a-member-function-on-a-non-object-in-functionsphp/#findComment-782205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.