[SOLVED] Sending data from FiveM to Website

What do you mean by “how would I do that?” Are you asking how a PHP script connects to a database in general? Connecting to a remote database with a PHP script is no different than connecting to a localhost db. The only thing you need to keep in mind is that the remote db host needs to be set up to allow remote connection for that db user.

Nono, apologies. Connect to a database on a webserver FROM the game server

I think it would be easier to save the data to your gameserver and then retrieve it with the PHP script on the webserver. With the webpanel I’m writing, I just run a cron every minute to handle all the data retrieval of players.json and MySQL.

Could I message you mate? Saves commenting constantly

you mentioned ajax, sounds like you need to go through an AJAX turotial and really understand what’s going on first.

But basically it’s a client (browser) making a POST via an http API to a webserver.

Exactly what you’re trying to do, and sounds like youre getting closer.

In your case the AJAX client making the POST would actually be FiveM rather than a browser and would be doing so with the PerformHTTP natives (FiveM’s http api’s).

For developing an AJAX api I would just follow a tutorial and test it using a browser and possibly a tool such as Postman. Make sure your API works and you understand it before you jump into trying to call it from FiveM.

You should be able to configure your webserver logs to see at least THAT the post happened, in some you may even be able to log the POST data but generally this isn’t done because it could be quite large depending on the application.

And your PHP API should return an HTTP success status code back to the client after it successfully processes the POST request as well, the HTTP API should give you access to this. So if your PHP code has some basic validation (as mentioned by another responder) and proper error handling, the code on the client side in FiveM should be able to determine as well if it’s working correctly or not (you can probably log or display the HTTP response code).

W3C schools probably has a good AJAX overview, start by following along and building out someone’s example to make sure you fully understand it before tyring to build your own.

Good Luck!

Blood brilliant, thanks for the tips mate

hey do you konw why a players server is unable to connect to the URL php i see no attempt to connect to the SQL however otherwise on the local browers they can pull up the php page?

and the SQL registers an attempt but not when connecting via the script in the server ?

i am stump other thank he has a port that is being blocked by the firewall ? i am not sure what to suggest to him

Could be many things…
It could be firewall related, av related, software related isssues hardware related issues…

Lets start with the os? Windows? Linux? What version?

If linux can he/she ping and use curl to get a response from the website/server?

If windows can he/she ping and use telnet to get a response from the website/server?

If above return with a pingable ip and a response then we know its not hardware/software/network related and could be code related.

thanks so much it was def on his end

i tried this same method sending the data from the server (to a node.js rest api) but in no case the api receives the actual data. It sees that the api is getting accesed but its not getting the data :confused:

 PerformHttpRequest('http://LinkToMyAPI/reportPlayer/KEY', function(err, text, headers) end, 'POST', json.encode({
            name = "test",
            grund = "Der Grund",
            reporter = "ich"
    }), { ['Content-Type'] = 'application/json' })

@123LladdCae did you find any solution?