I tried all possible methods and always got the same error, can someone help me?? and give me some advice? pdt. i am new to web development
thanks
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
$app->get('/api/products', function(Request $req, Response $res){
$query = 'SELECT * FROM products';
try{
$db = new database();
$db = $db->connection();
$stmt = $db->query($query);
$products = $stmt->fetch_object();
echo json_encode($products);
}catch(Exception $e){
echo $e;
}
});
$app->post('/api/add',function()use($app){
$request = Slim::getInstance()->request();
$name = json_decode($request->getBody());
//$content = file_get_contents($req);
//$json = json_decode($content, true);
//$post = $id->post;
echo $name;
});