I am facing one issue. I have one db-config file and once I am including this file to my php page I am not getting my input data.
create_user.php:
header("Access-Control-Allow-Origin: http://localhost/restapi/");
header("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
// files needed to connect to database
include_once 'config/database.php';
include_once 'objects/user.php';
// get database connection
$database = new Database();
$db = $database->getConnection();
echo 'data:::'.$_POST['firstname'];exit;
// instantiate product object
$user = new User($db);
The above is my php file where I am including the database file.
config/databse.php:
<?php
// used to get mysql database connection
class Database{
// specify your own database credentials
private $host = "localhost";
private $db_name = "users";
private $username = "root";
private $password = "**********";
public $conn;
// get the database connection
public function getConnection(){
$this->conn = null;
try{
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
}catch(PDOException $exception){
echo "Connection error: " . $exception->getMessage();
}
return $this->conn;
}
}
?>
After including the database file and calling the method when I am trying to print post param its coming blank. I am using PHP 7.
exiton this lineecho 'data:::'.$_POST['firstname'];exit;error_reportinganddisplay_errors<b>Fatal error</b>: Uncaught Error: Class 'Database' not found in /var/www/html/restapi/api/create_user.php:16.