title: Endpoint can't make a POST request properly in PHP using SLIM framework
body: <p>I'm trying to make a API server that is supposed to connect to a data base, using SLIM framework following this <a href="https://www.phpflow.com/php/create-simple-rest-api-using-slim-framework/" rel="nofollow noreferrer">tutorial</a>. Actually I made a endpoint who get data from the data base, but can't insert new one.</p>
  
  <p>Every time when I try to insert new data the POST parameters are nulls and the data base only send a error message.</p>
  
  <p>In my groupes.php I have the following:</p>
  
  <pre><code>&lt;?php
  
  use Slim\Http\Request;
  use Slim\Http\Response;
  
  // Routes
  
  $app-&gt;get('/[{name}]', function (Request $request, Response $response, array$args) {
     // Sample log message
     $this-&gt;logger-&gt;info("Slim-Skeleton '/' route");
  
     // Render index view
     return $this-&gt;renderer-&gt;render($response, 'index.phtml', $args);
  });
  
  $app-&gt;group('/api', function () use ($app) {
  
     $app-&gt;group('/v1', function () use ($app) {
         $app-&gt;get('/clients', 'getClients');
         $app-&gt;post('/make', 'addClient');
     });
  });
  </code></pre>
  
  <p>The code above is just to define two endpoits: <code>getClients</code> and <code>addClient</code>.</p>
  
  <p>And in my index.php I have:</p>
  
  <pre><code>function getConnection(){
      $dbhost = "127.0.0.1";
      $dbuser = "root";
      $dbpass = "dzpga883yRusPHhv";
      $dbname = "pruebaandroid";
      $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
      $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      return $dbh;
  }
  
  //method: GET
  //domain: mi-api/api/v1/clients
  function getClients($response){
      $sql = "SELECT * FROM cliente";
      try{
          $stmt = getConnection()-&gt;query($sql);
          $client = $stmt-&gt;fetchAll(PDO::FETCH_OBJ);
          $db = null;
  
          return json_encode($client);
      } 
  
      catch(PDOException $e){
          echo '{"error":{"text":'. $e-&gt;getMessage() .'}}';
      }
  }
  
  //method: POST
  //domain: mi-api/api/v1/make
  function addClient($request) {
      $client = json_decode($request-&gt;getBody());
  
      $sql = 'INSERT INTO cliente (nombre, apellido, cedula, direccion, telefono, email) VALUES (:nombre, :apellido, :cedula, :direccion, :telefono, :email)';
  
      try {
          $db = getConnection();
          $stmt = $db-&gt;prepare($sql);
          $stmt-&gt;bindParam(":nombre", $client-&gt;nombre);
          $stmt-&gt;bindParam(":apellido", $client-&gt;apellido);
          $stmt-&gt;bindParam(":cedula", $client-&gt;cedula);
          $stmt-&gt;bindParam(":direccion", $client-&gt;direccion);
          $stmt-&gt;bindParam(":telefono", $client-&gt;telefono);
          $stmt-&gt;bindParam(":email", $client-&gt;email);
          $stmt-&gt;execute();
          $client-&gt;id = $db-&gt;lastInsertId();
          $db = null;
          echo json_encode($client);
      } 
  
      catch(PDOException $e){
          echo '{"error":{"text":'. $e-&gt;getMessage() .'}}';
      }
  }
  </code></pre>
  
  <p>So, using postman to do a GET request to <code>mi-api/api/v1/clientes</code> retrieve all the data as spected, but whhen I try with a POST request <code>mi-api/api/v1/make?nombre=asdf&amp;apellido=asdf&amp;cedula=asdf&amp;direccion=asdf&amp;telefono=asdf&amp;email=asdf</code> it's supposed to insert the new information but postman give me the following error:</p>
  
  <pre><code>{"error":{"text":SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'nombre' cannot be null}}
  </code></pre>
  
  <p>Looks like the <code>addClient</code> function  it's not geting the parameters, so it's taking it as null. Why is this happening? I don't know what is wrong here, any response is welcome.</p>
  
  <p>See the image
  <a href="https://i.stack.imgur.com/Q0pt1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q0pt1.png" alt="enter image description here"></a></p>
  
  <p>PD: yes, the DB is well formated, it have a id as PK auto increment and I tryed to print <code>echo client-&gt;nombre</code> and prints nothing but the error.</p>