I have Connection class and Operations class when call the required method which is used to insert the record to the database , that shows the error.
File Name : Connection.php
<?php
/**
* Connection class to make "connection" with database
*/
class Connection
{
public $host;
public $user;
public $password;
public $databaseName;
/**
* Constructor
*/
public function __construct()
{
$this->host = '';
$this->user = '';
$this->password = '';
$this->databaseName = '';
$this->connect();
}
/**
* The method that make the connection to the database
*/
Connection method which is used to establish the connection
public function connect()
{
$con = mysqli_connect($this->host, $this->user, $this->password, $this->databaseName);
if(!$con){
echo "Connect to the database failed";
}
return $con;
}
}
FIle Name : Operations.php
require_once"Connection.php";
class Operations
{
//$Connection = new Connection();
//$con = $Connection->connect();
function __construct()
{
$Connection = new Connection();
$con = $Connection->connect();
}
When i call this following function, it's show me the error
public function add_main_menu($title, $title_ara, $image)
{
$sql = "INSERT INTO menu (title, title_ara, image) VALUES ('$title', '$title_ara', '$image')";
$result = mysqli_query($con, $sql);
return $result;
}
public function add_sub_menu($title, $title_ara, $price, $description, $descreption_ara, $image, $menu_id){
$sql = "INSERT INTO sub_menu (title, title_ara, price, description, description_ara, image, menu_id) VALUES ('$title', '$title_ara', $price, '$description', '$description_ara', '$image', '$menu_id')";
$result = mysqli_query($con, $sql);
return $result;
}
}