How do I Insert Data into MySQL using AJAX?

0 favourites
  • 10 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I am struggling here. I have followed almost every tutorial I could fine about this and it still isn't working. So I am trying to insert data into MySQL using Ajax. It just won't insert into the database no matter what I try.

    I even created a simple test html form to make sure my PHP was working, and it worked fine and entered the data into the database I put in the form.

    Here is what I have in Construct 3

    I used to have it just on clicked on the button to trigger the AJAX, but thought that maybe I had it wrong and I need to do it with mouse. That didn't work either. Any help would be appreciated.

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • May be an issue with cross-origin requests. Press F12 in browser and see if there is any error message in Console. Then try googling it :)

  • Looking at your image it would appear your trying to post via HTTP. This won't work if the game is hosted on a HTTPS domain ( such as preview ) because browsers disallow it for security reasons. You may also have issues with CORS if your server isn't configured for it.

  • So testing it by exporting it to nw.js or something would be the only way to see if its working?

  • Well generally I would just advise using a host that supports HTTPS, browsers quite aggressively prefer them nowadays.

    Exporting as a HTML game and putting it on a local HTTP server would work. Using something like XAMPP, MAMP or simple-http-server.

  • Your can normally get free https with some of these options below.

    https://geekflare.com/free-ssl-tls-certificate/

  • Well generally I would just advise using a host that supports HTTPS, browsers quite aggressively prefer them nowadays.

    Exporting as a HTML game and putting it on a local HTTP server would work. Using something like XAMPP, MAMP or simple-http-server.

    Well its my own dedicated server. I could change it support https if I knew what setting it was, or how to do it. Any ideas on what I could change?

    Right now I have the MYSQL database remote, and my php files on another server. The web server has been allowed to use the remote server by setting the IP of the web server as allowed in MySQL. I checked that it works by doing a simple html form from the web server. So connection, and input is working. I guess I just need to figure out the exact server setting to allow https posts.

  • There's some info here, I don't know how relevant it is to your situation.

    https://developers.google.com/web/fundamentals/security/encrypt-in-transit/enable-https

  • Son of a gun! That was it. I just installed a free SSL certificate from Comodo to test, and it worked right away....many many hours trying to figure out if my code was wrong, if construct was wrong all to find out it was just that it needed an SSL certificate....bah!

    Thanks for all the help, you helped a lot. I appreciate it.

  • SSL is a fun hurdle, but at least you know a bit about it now!

    If you have issues with networking in future I recommend looking up how to use the Chrome Developer tools, it has an excellent networking tool for checking what requests a page is making. With contents, response, headers, errors. All that jazz.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)