Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Posting data to PHP problems?

Asked by
Troxure 87
6 years ago

So my goal is to post data to php so it can be stored in SQL and stuff like that. When I run the game on studio (yes httpservices are enabled) it does post and adds +1 columns on the table in phpmyadmin with SQL, but the data is empty and 'Rank' is 0.

I'm trying to get it to store the data sent from roblox correctly to SQL.

Here's what I've got so far...

The script in studio:

local httpServ = game:GetService("HttpService")
sendData = '?Rank=1&Color=Really%20red&Reason=nothing'
local res, data = pcall(function()
    return print(httpServ:PostAsync('thewebsite', sendData)) 
end)

this outputs:

<html>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<h1 style="font-size:60px;">Script index form<br></h1>
Established a connection with given host successfully.<br>Successfully accessed databased specified.<br>Array
(
)

The PHP and html

<html>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<h1 style="font-size:60px;">Script index form<br></h1>
<?php
$host = "fdb19.awardspace.net";
$username = "2626551_roblox";
$password = "-----";
$Rank = $_POST["Rank"];
$Color = $_POST["Color"];
$Reason = $_POST["Reason"];
$connection = mysqli_connect($host, $username, $password);
$sql = "INSERT INTO roblox (Rank, Color, Reason) VALUES ('$Rank', '$Color', '$Reason')";
if(!$connection){
  echo "Couldn't establish a connection with the given host, user and pass.<br>";
}else{ echo "Established a connection with given host successfully.<br>"; }
if(!mysqli_select_db($connection, $username)) {
  echo "Could not access the database specified.<br>";
}else{ echo "Successfully accessed databased specified.<br>"; }
if(isset($_POST["Rank"])) {
if (!mysqli_query($connection, $sql)) {
    echo "Could not add data in to the table.<br>";
}else{ echo "Added data into table successfully.<br>"; }
echo "Results :: Rank: " .$Rank. " | Color: " .$Color. " | Reason: " .$Reason ."<br>";
}
print_r($_GET) // Outputs Array () which should have the data inside of it, but does not...
?>

Help would be greatly appreciated, thanks...

0
Pls do not use this code it is not a secure way to do this. If you need an example of how to send a POST request in roblox take a look at https://forum.scriptinghelpers.org/topic/44/using-the-httpservice-in-roblox User#5423 17 — 6y
0
Yes thank you after hours of trying i just fiddled with it, great job thank you so much! Troxure 87 — 6y
0
Any ideas to how i would send the data back to roblox? Troxure 87 — 6y
0
Its common for an API to return a JSON User#5423 17 — 6y
View all comments (3 more)
0
Why not just use datastores in ROBLOX? hiimgoodpack 2009 — 6y
0
Not really an answer, but you might want to use "local res, data = pcall(function() return httpServ:PostAsync('thewebsite', sendData) end) print(data)" to use the data variable. hiimgoodpack 2009 — 6y
0
yeah thats what i did thanks Troxure 87 — 6y

Answer this question