0

session.php

include("database.php");

function addPOTW($subweek, $subtitle, $subcaption, $subsubmittedby)
{
    global $database, $form;
    /* Errors exist, have user correct them */
    if ($form->num_errors > 0) {
        return 1; // Errors with form
    }
    /* No errors, add the new POTW to the database */
    else {
        if ($database->addNewPOTW($subweek, $subtitle, $subcaption, $subsubmittedby, $subfile)) {
            return 0; //Event signup added succesfully
        } else {
            return 2; //Event signup attempt failed
        }
    }
}

This is my function, "addPOTW", located in the file session.php (with useless parts redacted). For some reason, I keep getting the error message: "Fatal error: Call to undefined method MySQLDB::addNewPOTW()" even though it's defined right here:

database.php

class MYSQLDB {
    function addNewPOTW($date, $title, $caption, $submitter, $filepath)
        {
            $q = "INSERT INTO `" . TBL_POTW . "` VALUES ('','$date','$title','$caption','$submitter','$filepath')";
            return mysql_query($q, $this->connection);
        }
}

I have other functions in session.php accessing functions in database.php using the $database variable in the exact same way, and they work perfectly fine. Any ideas why only this one function is being reported as undefined??

2
  • Are you sure the version of database.php being used in the application is the same one you're looking at? Commented Dec 22, 2011 at 5:31
  • Also try var_dump($database) right before you call the method. Commented Dec 22, 2011 at 5:32

1 Answer 1

2

Because you are referring to $this, you would need to instantiate an object from that class and then call the method.

Something like this should get it working...

$database = new MYSQLDB;

Make sure you have it in scope before your addPOTW() function.

Sign up to request clarification or add additional context in comments.

4 Comments

Can't use static as it makes use of $this
@Phil: Thanks, didn't notice that. Fixed.
I believe the global (eww) $database is meant to be an instance of MYSQLDB. FYI, unless indicated by public, protected or private keyword, class methods (functions) are implicitly public
@Phil: Yeah, that's what I assumed. Everything public except noted otherwise is a relic from PHP4's OO implementation I believe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.