0

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;
});
  • 1
    Possible duplicate of [500 internal server error with POST request - Slim framework](https://stackoverflow.com/questions/37189603/500-internal-server-error-with-post-request-slim-framework) – Nipun Aug 11 '17 at 04:35

1 Answers1

1

Follow the tutorial. You need to require Composer's autoloader.

If you check your PHP error log, you'll see the errors.

Rob Allen
  • 12,444
  • 1
  • 35
  • 46