I am trying to get RoScript's PhP Login script to work properly and have blown through a lot of errors myself. Right now I am trying to get the coding down in order to require an Administrator to be logged on to view a page.

Fatal error: Call to a member function qstr() on a non-object on line 340

line 340 on functions.php:

$query = "SELECT `Level_access` FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $id );

content.php

<?php
	session_start();

//Set Inclue Path
function setinclude(){
    $levels = substr_count($_SERVER['PHP_SELF'],'/');
    $root = '';
    for($i = 1; $i < $levels; $i++){$root .= '../';}   
    set_include_path($root);
}      
setinclude();

require_once('login/db.php');
include('login/functions.php');

if ( isadmin ( $_SESSION['user_id'] ) ):
?>

HTML FORM CODE HERE!

<?php
	endif;
?>

functions.php lines 325-357

	// ------------------------------------------------------------------------

/**
 * Is admin - Determines if the logged in member is an admin
 *
 * @access	public
 * @param	string
 * @return	bool
 */


function isadmin ( $id )
{
	global $db;

	$query = "SELECT `Level_access` FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $id );

	if ( $db->RecordCount ( $query ) == 1 )
	{
		$row = $db->getRow ( $query );

		if ( $row->Level_access == 1 )
		{
			return TRUE;
		}
		else {
			return FALSE;
		}
	}
	else {
		return FALSE;
	}
}

    It is saying that $db is not an object. I can see you include db.php but does that file also instantiate the object?

      m@tt;10879615 wrote:

      It is saying that $db is not an object. I can see you include db.php but does that file also instantiate the object?

      I figured as much with it calling for $db. However I am not quite sure what it is looking for as $db.

      <?php
          $link = mysql_connect('localhost', 'user_name', 'password');   
      $select = mysql_select_db('database_name', $link); ?>

      I have tried to add the following code it didn't work.

      $db=$select
      

        What are the contents of db.php?

          oops, sorry I put the code up there but didn't label it.

          db.php

          <?php
              $link = mysql_connect('localhost', 'user_name', 'password');   
          $select = mysql_select_db('database_name', $link); ?>

            It's quite obvious you are missing the database class. There are several functions being called, for example $db->getRow and $db->qstr.

            It would be instantiated using something like $db = new Db

              I understand that I need to define $db in the db.php. However I am still a newbee PHP/MySQL programmer and I can't figure out exactly want it wants in there in order to process correctly.

              is it wanting something like?

              $db = mysql_select_db('database_name', $link);

                No, you are missing the class required to run your code.

                This is what a class looks like:

                <?php
                class Db
                {
                	function Db( ) { }
                	function qstr( ) { }
                	function getRow( ) { }
                }
                
                $db = new Db;
                ?>

                  Thanks! that Got it done then I done! I've worked through a few more errors and now I'm not getting one just a blank page (besides the "You're logged in").

                  I'm assuming it has something to do with the if and/or endif statement.

                  Form.php

                  <?php
                  
                  //Set Inclue Path
                  function setinclude(){
                      $levels = substr_count($_SERVER['PHP_SELF'],'/');
                      $root = '';
                      for($i = 1; $i < $levels; $i++){$root .= '../';}   
                      set_include_path($root);
                  }      
                  setinclude();
                  
                  include('login/auth.inc');
                  require_once ('login/settings.php');
                  require_once('login/db.php');
                  include('login/functions.php');
                  
                  if ( isadmin ( $_SESSION['user_id'] ) ):
                  ?>
                  
                  HTML FORM CODE
                  
                  <?php
                  	endif;
                  ?>
                  

                  auth.inc (just in case)

                  <?php session_start(); 
                  if (!isset($_SESSION["user_id"])) { 
                  echo "You must be logged in to view this page"; exit; 
                  } 
                        else { 
                  echo "Hello, you're logged in!"; 
                  }
                  ?>
                  
                    Write a Reply...