0

I'm trying to get data from the post to insert into the database, but can't get it to work. This is my code:

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require 'vendor/autoload.php';
require "classes/Autoloader.php";

$app = new \Slim\App;

$app->post('/', function(Request $request, Response $response) use ($app) {

    $postVars = $request->getParsedBody();

    $id = $request->getAttribute('id');
    $steps = $request->getAttribute('steps');
    $date = $request->getAttribute('date');

    require_once "classes/Connection.php";
    $userdata = new Insert($dbh, $id, $steps, $date);
    $userdata->insert();
});
$app->run();

I'm doing a post request with Postman at localhost/wp-api/?id=1&steps=12&date=8787, but when I try to check the variables, I don't get anything, and checking the $request reveals the following error: Named entity expected. Got none in the same line as this: [query:protected] => id=1&steps=12&date=8787.

Sources I checked for fixes:

What I tried:

  • Replacing all & for %26

  • Using an url with only one value (so I don't have to use & anywhere

I think the issue comes from the &, although I might be wrong. The rest of the script works, and even does insert stuff (although null values), so the problem seems to just be getting the values from the url.

Thanks in advance for any help!

Newbb
  • 33
  • 6

0 Answers0