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
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']);
You are trying to call a private method outside the class, that's not possible, you can read more about methods visibility on the official PHP methods visibility docs.
Class members declared public can be accessed everywhere. Members declared protected can be accessed only within the class itself and by inheriting and parent classes. Members declared as private may only be accessed by the class that defines the member.
You should declare your method as public instead of private if you want to use the method outside the class:
public function insertData($airport, $location, $space , $flight){
... your code
}