Jassie Posted May 2, 2021 Share Posted May 2, 2021 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 Quote Link to comment Share on other sites More sharing options...
BillyKane Posted May 7, 2021 Share Posted May 7, 2021 (edited) 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 May 7, 2021 by BillyKane Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.