I’m pretty new to coding and need some guidance on building a web-based adventure game.
I want to create a simple adventure game that runs in a web browser. My plan is to use MySQL for storing game data, HTML/CSS for the interface, JavaScript for game logic, and PHP to handle database connections.
I found a tutorial that showed me how to send data from JavaScript to PHP like this:
function sendRequest() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
// handle response
};
xhr.open("GET", "getData.php?playerID=" + playerId, true);
xhr.send();
}
And the PHP side looks like:
$playerId = $_GET["playerID"];
$query = "SELECT * FROM players WHERE player_id = '" . $playerId . "'";
My main concerns are:
- This approach only works with one specific table and query type
- I need to access different tables (inventory, quests, stats, etc.)
- Security is a big worry - if someone looks at my JavaScript code, they could see how to manipulate my database
Should I create separate PHP files for each type of database operation? How do I prevent people from exploiting my database endpoints? What’s the standard approach for handling multiple database operations securely in browser games?