Home>

There is such a code on SLIM, you must output HTTP statuses in errors. Do not really understand it. Direct young mind.

$ app->
Post ('/Products', Function (ServerRequestInterface $ Request, ResponseInterface $ Response, $ Next) USE ($ App) {
    Global $ MySQL;
    $ postjson= $ Request->
getparsedbody ();
    Echo "$ Postjson [DU]";
    $ Query= "Insert Into` Tate` (`du`,` name`, `Price`) Values ​​('$ Postjson [DU]', '$ Postjson [Name]', '$ Postjson [Price])";
    if ($ result= mysqli_query ($ MySQL, $ Query)) {
        Echo "All cool";
    } ELSE {
        echo mysqli_error ($ MySQL);
    }
    Echo $ Response;
});
  • Answer # 1

    Not through Echo. have to do. Need something like this:

    $ app->
    Post ('/Products', Function (ServerRequestInterface $ Request, ResponseInterface $ Response, $ Next) USE ($ App) {
        Global $ MySQL; //it is very bad, look about the introduction of dependencies
        $ postjson= $ Request->
    getparsedbody ();
        $ Body= $ Response->
    getBody ();
        $ BODY->
    Write ($ Postjson ["du"]);
        $ Query= "Insert Into` Tate` (`du`,` name`, `Price`) Values ​​('$ Postjson [DU]', '$ Postjson [Name]', '$ Postjson [Price])";
        if ($ result= mysqli_query ($ MySQL, $ Query)) {
            $ BODY->
    Write ("cool");
            Return $ Response;
        } ELSE {
            $ BODY->
    Write (Mysqli_error ($ MySQL));
            Return $ Response->
    Withstatuscode (500);
        }
        Return $ Response;
    });