1
public  function upload() {

    try {
        $database_connect = new DatabaseConnect();
        $connection = $database_connect->getConnection();

        $this->populate_database($connection); //line 43
        $connection->close();

        return true;

    } catch (Exception $exp) {
        echo $exp->getMessage();
        return false;

    }

}

private function populate_database(mysqli $connection){
    $query = "insert into bases (img_url) values ($this->image_name)";
    $result = $connection->query($query);

    if (!$result) die($connection->error);

    if (!$this->update_linked_table($connection)) {
        echo "linked table not updated";
    }
}

i am calling a private non-static method then why am i getting this error:

Fatal error: Using $this when not in object context in /var/www/html/CocExplore/html5BoilerPlate/php/LocalImage.php on line 43

War10ck
  • 12,387
  • 7
  • 41
  • 54
user3555371
  • 238
  • 1
  • 7

1 Answers1

0

Call methods non statically. For example, if you call YourClass::upload(), replace it to something like $class = new YourClass(); $class->upload();

Nick
  • 9,735
  • 7
  • 59
  • 89