Uncaught Error: Call to private method DbOperations::insertData() from context ''

后端 未结 2 1499
一个人的身影
一个人的身影 2021-01-24 05:29

When I\'m trying to insert data trough the database its says \"Uncaught Error: Call to private method DbOperations::insertData() from context \'\'\".

My insert data PHP

2条回答
  •  粉色の甜心
    2021-01-24 06:19

    You cannot call private methods or fields outside class

    Either make the function insertData() public by defining it as follows

    public function insertData() {
        ************
    }
    

    or call it from constructor using

    function __construct($airport, $location, $space , $flight){
        $db = new DbConnect();
    
        $this->con = $db->connect();
    
        $this->insertData($airport, $location, $space , $flight);
    
    }
    

    run it as follows:

    $db = new DbOperations($_POST['airport'], $_POST['location'], $_POST['space'], $_POST['flight']);
    

提交回复
热议问题