How do I use HttpService:PostAsync() to post to a PHP Script

So I have a system used for sending player data to a database so it can be logged.
(All sensitive data has been replaced with other values)

local parameterName = "LOG_VALUE"
for i,v in pairs(service.Players:GetChildren()) do
					if v:FindFirstChild(parameterName) then
						local ExportValue = v:FindFirstChild(parameterName).Value
						local URL = "https://urlhere/api/v1/logger.php"
						local Data = {
							["key"] = "key";
							["LogName"] = "PETCM_LOG";
							["Username"] = v.Name;
							["UserID"] = v.UserId;
							["Points"] = ExportValue;
							["Division"] = "PETCM"
						Data = http:JSONEncode(Data)
						local response = http:PostAsync(URL,Data)

And on Server-Side (PHP) I have:

 echo('{"Status": "API_KEY"}');
 $APIKey = "key";
 $PostKey = $_POST['key'];

 if($APIKey != $PostKey){
  echo('{"Status": "API_KEY"}');
  $Connection = mysqli_connect("address","username","password","database");
   $LogName = $_POST['LogName'];
   $LogUser = $_POST['Username'];
   $LogUserID = $_POST['UserID'];
   $Points = $_POST['Points'];

   $LogTable = $_POST['Division'].'Logs';

   $InsertQuery = $Connection->query("INSERT INTO ".$LogTable."(LogName,LogUser,LogUserId,LogPoints) VALUES(".$LogName.",".$LogUser.",".$LogUserID.",".$Points.");");
   echo('{"Status": "LOGGED"}');

I get no errors when running this code, but when I print the response in roblox, the var_dump from PHP shows there’s nothing in the $_POST data. Did I use incorrect methods on PHP or roblox, or where does my issue lie?

1 Like

If you are trying to return data from your php script into HttpService GetAsync, I don’t think that’s possible. Why are you using FindFirstChild(“ParameterName”) when it definitely exists?

1 Like

When you post JSON content, the data will not be stored in $_POST. Use file_get_contents("php://input"); instead.

1 Like