Jump to content

Database in phaser 3


Recommended Posts

Hello, new to phaser and game development. I recently made a game but want to store the values like player position, coins collected and save the game state in a SQL database in phpmyadmin. Problem is I don't know how to do that.  Please help me I have a deadline in 5 days. All of my code is available here

Link to post
Share on other sites

the simple way is using ajax

send your coins value to insert php file

such as

var coins = 100; 
$.ajax({
                    type: "GET",
                    url: "https://yoursite/php/insert.php?collectdata="+coins,
                    data: dataString,
                     ...
                    beforeSend: function() {
                        //dosometing
                    },
                    success: function(data) {
                        if (data == "success") {
                           //dosometing
     
                        } else if (data == "error") {
                          //dosometing
                        }
                    }
                });
 ?>

 

and create insert.php put in your host

<?php
 include "db.php";
 if(isset($_GET['collectdata']))
 {
 $coins=filter_var($_GET['collectdata'], FILTER_SANITIZE_STRING);
 $q=mysqli_query($con,"INSERT INTO `game_data` (`coins`) VALUES (' $coins')");
 if($q)
  echo "success";
 else
  echo "error";
 }
?>

 

Edited by BillyKane
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...