Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8425549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:18:04+00:00 2026-06-10T04:18:04+00:00

I keep getting an ‘Undefined variable’ notice when I call on an object I

  • 0

I keep getting an ‘Undefined variable’ notice when I call on an object I ‘think’ I have instantiated, but apparently haven’t. I can’t put a finger on my the error. The object is $fgmembersite, according to my error messages it doesn’t exist, I’m confused about why. It maybe a simple case of me messing up my directories in the include/require portion of my scripts but I’ve been looking at them and can’t see anything wrong. Tell me if you guys want to look at my file hierarchy.

And again thanks for the help!

I have three PHP files that are at play.

First one is login-home.php

<?PHP
require_once("./profile_settings/view.php");

if(!$fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("login.php");
    exit;
}
?>

/*a bunch of stuff*/
<img id="profile_avatar" src="profile_settings/<?php echo fetchAvatarLocation(); ?>"></img>
/*a bunch of stuff*/

Next I have view.php which holds a function I use to generate the path-name of where I store my picture.

<?php 
include("./include/membersite_config.php");

    function fetchAvatarLocation()
    {
        $user_id = $fgmembersite->UserId();
        $query = mysql_query("SELECT * FROM ddmembers WHERE id_user = '$user_id'");
        if(mysql_num_rows($query)==0) 
            die("User not found!");
        else
        {
            $row = mysql_fetch_assoc($query);
            $location = $row['imagelocation'];
            return $location;
        }
    }
    ?>

And finally I have membersite_config.php

<?PHP
include("fg_membersite.php");

$fgmembersite = new FGMembersite();

//Provide your site name here
$fgmembersite->SetWebsiteName('Mysitename.com');

//Provide the email address where you want to get notifications
$fgmembersite->SetAdminEmail('My.Email@Provider.net');

//Provide your database login details here:
//hostname, user name, password, database name and table name
//note that the script will create the table (for example, fgusers in this case)
//by itself on submitting register.php for the first time
$fgmembersite->InitDB(/*hostname*/'localhost',
                      /*username*/'user',
                      /*password*/'password',
                      /*database name*/'database',
                      /*table name*/'table');

//For better security. Get a random string from this link: http://tinyurl.com/randstr
// and put it here
$fgmembersite->SetRandomKey('**************');

?>

fg_membersite is a file that contains the class fgmembersite that stores a bunch of functions, the ones that I need it for are…

function UserId()
    {
        return isset($_SESSION['userid_of_user'])?$_SESSION['userid_of_user']:'';
    }

    function UserName()
    {
        return isset($_SESSION['username_of_user'])?$_SESSION['username_of_user']:'';
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:18:06+00:00Added an answer on June 10, 2026 at 4:18 am

    The object is not in the scope of the function, so it is undefined. You need to pass it in as a parameter:

    function fetchAvatarLocation( $fgmembersite)
    

    Then call it with the object as a parameter:

    <img id="profile_avatar" src="profile_settings/<?php echo fetchAvatarLocation( $fgmembersite); ?>"></img>
    

    An alternative is to use global variables, but I wouldn’t recommend it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting a undefined index error on my page. I have tried different
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition
I keep getting this error and have no idea why. I googled and scanned
Keep getting The constructor SimpleCursorAdapter(MyProgram, int, Cursor, int) is undefined and am not sure
I keep getting this whenever I run the below code: Fatal error: Call to
I keep getting the same error when I try to set an attribute but
I keep getting the ' Object Expected ' error within my page script when
I keep getting this error from my code and I have no idea what
I keep getting this error and i have been trying everything for about a
I keep getting the error element is undefined var validator = $.data(element.form, 'validator'); on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.