Why the php//input returns empty string?

I write on Vue simple application using axios make a request for a simple crud api in php to interact with mysql database the bottom line is that connected to the database, you can execute a query it works, but can't get the settings from the php//input constantly returns an empty string, the query looks like this : POST reference/api/ajax.php?request=1 the server responds, but responds with empty strings.
my ajax.php
<?php
include "config.php"; // connect to database

$data = json_decode(file_get_contents("php://input"));
$request = $data->request;

if($request == 1){
 $userData = mysqli_query($con, "select * from rows");

 $response = array();

 while ($row = mysqli_fetch_assoc($userData)) {
 $response[] = $row;
}
 echo json_encode($response);
}
if($request == 2){
 $platform = $data->platform;
 $container1 = $data->container1;
 $container2 = $data->container2;
 $ZPU1 = $data->ZPU1;
 $ZPU2 = $data->ZPU2;
 $reportId = $data->reportId;
 mysqli_query($con, "INSERT INTO rows(platform,container1,container2,ZPU1,ZPU2,reportId) VALUES('" . $platform . "','" . $container1 . "','" . $container2 . "','" . $ZPU1 . "','" . $ZPU2 . "','" . $reportId . "')");
 echo "Insert successfully";
}

exit;


I would be grateful for any help
March 20th 20 at 11:40
1 answer
March 20th 20 at 11:42
Try.
$json = file_get_contents('php://input');
$obj = json_decode($json);
Did as you suggested, nothing changed
changed the code so:
$json = file_get_contents('php://input');
$obj = json_decode($json);
$request = $obj->request; - Marian_Effertz68 commented on March 20th 20 at 11:45

Find more questions by tags PHP