0

php Code:

header('Content-Type: text/plain');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$decoded = json_decode(file_get_contents('php://input'));

$db = new PDO('mysql:host=localhost;dbname=###', '###', '###');

$prepared = $db->prepare('INSERT INTO ActiveServerData (GameName, GameId, GameOwner, GameMax, ServerId, ServerCurrent, ServerRunning, PendingCommand) VALUES (:Arg1, :Arg2, :Arg3, :Arg4, :Arg5, :Arg6, :Arg7, :Arg8)');
$prepared->execute((array) $decoded);

header('HTTP/1.1 200 OK');
print_r(json_encode($decoded));
} else {
header('HTTP/1.1 405 METHOD NOT ALLOWED');

echo '405 METHOD NOT ALLOWED';
}

Basically, I am attempting to send data using ROBLOXs PostAsync function, here is what I am sending;

local Connection = Server.Requires.WebAPI.PostData(Server.Game.GameName,Server.Game.GameID,Server,Server.Game.GameOwnerName,Server.Game.GamePlayerMax,Server.Server.ServerID,Server.ServerPlayerCount,"Admin","Nil")
warn(Connection)

This includes both strings, and number values. Below is the function that actually sends the data to the site.

WebAPI.PostData = function(Arg, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)
local   http    =   game:GetService('HttpService')
local currentData = {
            ['Arg1']    = Arg;
            ['Arg2']    = Arg2;
            ['Arg3']    = Arg3;
            ['Arg4']    = Arg4;
            ['Arg5']    = Arg5;
            ['Arg6']    = Arg6;
            ['Arg7']    = Arg7;
            ['Arg8']    = Arg8;

        }
        local jsonData = http:JSONEncode(currentData)
        local newData  = http:PostAsync(
                                        WebAPI.WebConnections.DeerSystems .. "/Secure/connect.php",
                                        jsonData,
                                        Enum.HttpContentType.ApplicationUrlEncoded
        )

        return newData
 end

I get a return of the data, thats what should happen, however when I check the table nothing was inserted...

  • By default, PDO errors silently. Make it throw a useful exception. `$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);` – Michael Berkowski Jan 23 '17 at 03:21
  • Also, pass `TRUE` as the second argument to `json_decode()` to make it produce an associative array rather than a `stdClass`, which will help avoid casting it with `(array)` later. http://php.net/manual/en/function.json-decode.php – Michael Berkowski Jan 23 '17 at 03:23
  • You didn't post debug output for `var_dump($decoded)` before it was passed to `execute()`. Please do. – Michael Berkowski Jan 23 '17 at 03:24

0 Answers0