How to get data from PHP database?
Asked by
4 years ago Edited 4 years ago
Hello, I was trying to make a system to store players datas inside a database that I own instead of datastores because datastores have a limit. I figured out how to make the script to send datas, but not how to get the datas saved. I tryed things but somehow I can't figure it out. Can semeone help me? Thanks
Current script:
01 | local HttpsService = game:GetService( 'HttpService' ) |
02 | local domain = won't share it :p |
04 | game.ReplicatedStorage.Remote.SendData.OnServerEvent:Connect( function (plr,sent) |
05 | local sucess = pcall ( function () |
06 | HttpsService:PostAsync(domain, "name=" ..plr.Name.. "&age=" ..sent, 2 ) |
10 | print ( "Error When Communating To: DATABASE" ) |
16 | game.Players.PlayerAdded:Connect( function (Player) |
17 | local Leaderstats = Instance.new( 'Folder' ) |
18 | Leaderstats.Name = "Leaderstats" |
20 | local value = Instance.new( 'StringValue' ) |
22 | value.Value = HttpsService:GetAsync(domain, true ) |
script in my server: (index.php)
03 | <title>Data from Roblox</title> |
04 | <h 3 >Data from Roblox</h 3 > |
08 | $name = $_POST [ "name" ] ; |
10 | $con = new mysqli( "localhost" , "nani" , "nani" , "nani" ); |
11 | if (mysqli_connect_errno()) { |
12 | echo(mysqli_connect_error()); |
14 | if ($name! = NULL and $age ! = NULL) { |
15 | $con->query( "INSERT INTO main (name,age) VALUES ('$name','$age')" ); |
17 | $result = $con->query( "SELECT * FROM main" ); |
18 | if ($result->num_rows > 0 ) { |
20 | while ($row = $result->fetch_assoc()) { |
21 | echo($row [ "name" ] . ": " . $row [ "age" ] . "" ); |
25 | echo( "Database is empty" ); |
Should I change something to make it receive datas?