We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Fatal error: Call to a member function query() on a non-object

Development and Programming

SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

I have no idea why this error is happening, it’s shown in all the expressionengine tutorials and on the forums yet for some reason I still get it? line 43 is shown in the script

class upload_pictures
{
    public function upload_pictures()
    {
        if (!isset($whats_gonna_happen))
        {
           $uploads='';
           $cout=1;
            if (!table_exists('albums'))
            {
                                    //line 43 below
                $this->EE->db->query("CREATE TABLE albums(
                    id INT NOT NULL AUTO_INCREMENT,
                    PRIMARY KEY(id)
                    name VARCHAR(50)
                ") or die(mysql_error());
            }
            $stuff=$this->EE->db->query('SELECT id, name FROM albums');

help?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

Hi SDuke & welcome 😊

In order to get access to the “EE super object” you have to add one more line. Right after your function’s opening brace add “$this->EE =& get_instance();” so your code looks like this:

class upload_pictures
{
    public function upload_pictures()
    {
        $this->EE =& get_instance();
        if (!isset($whats_gonna_happen))
        {
           $uploads='';
           $cout=1;
            if (!table_exists('albums'))
            {
                                    //line 43 below
                $this->EE->db->query("CREATE TABLE albums(
                    id INT NOT NULL AUTO_INCREMENT,
                    PRIMARY KEY(id)
                    name VARCHAR(50)
                ") or die(mysql_error());
            }
            $stuff=$this->EE->db->query('SELECT id, name FROM albums');
       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

Thank you.

       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

do I need that for every function or just the constructor one?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

Just put it in your constructor and you’ll be great since __construct() fires with each instantiation of your class.

       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

thanks a lot :lol:, sorry but one more question. This is supposed to be a photo album, what I want is to make it so that the upload page is in the cp of expressionengine ( or just accesible there ) so nobody can do some url hacking to get into it. How would I do this?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team
sorry but one more question.

Never be sorry for asking a question! 😊

…what I want is to make it so that the upload page is in the cp of expressionengine ( or just accesible there ) so nobody can do some url hacking to get into it. How would I do this?

You’ll need a MCP file for that. Take a look through the Module Development Tutorial if you haven’t already. This part in particular: http://ellislab.com/expressionengine/user-guide/development/module_tutorial.html#control_panel_file

       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

thanks again :D, I do remember reading that, but I thought it was in the plugin tutorial. So when I went back to find it, obviously, I didn’t.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.