I can't get request params from php//input, it's always returning empty string. $_POST is also always empty, the only way I could get params is using $_REQUEST, and I'm not sure if it's right way to solve this problem.
var_dump(file_get_contents("php://input"));
returns: string(0) ""
var_dump($_POST);
returns: array(0) { }
var_dump($_REQUEST);
returns: array(2) { ["ergerg"]=> string(6) "ergerg" ["regergerg"]=> string(6) "ergreg" }
My request in Postman looks like :
POST /api/ajax.php?ergerg=ergerg®ergerg=ergreg
response
Status:200 OK
Time:192 ms
Size:236 B
ajax.php
<?php
include "config.php";
$rest_json = file_get_contents("php://input");
$obj = json_decode($rest_json);
$request = $obj->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;
in config file there is just connection to mysql database :
config.php
<?php
$host = "localhost"; /* Host name */
$user = "root"; /* User */
$password = "password"; /* Password */
$dbname = "dbname"; /* Database name */
$con = mysqli_connect($host, $user, $password,$dbname);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}