Hi all,

My name is Mike and am a completely blind gamer/computer hobbyist.

I am attempting to create an online web based single player game in which people can register so the stats, currency etc gathered are safekept and retrievable when someone wishes to continue playing. The data is stored in a mysql database.

For now however i am still designing stuff and trying stuff out, and, mainly learning.

I will describe the scenario i am encountering below and will ask my question afterwards:

on the town square of the elfen city allalhill there will be an option labled: Search for gold. When a player clicks on it the player should receive 2 gold pieces. In this example, the players goldcount should be increased by 2.

How can i write the php code so the player who clicked the 'search for gold' option receives 2 gold?

I have searched for the answer for half of the night but didn't find anything satisfieing. I am mainly wandering out in the dark, wondering of what i find is what i seek ... I haven't included anything inside the pages code yet. Also, i am really hope someone here can help me to learn what i seek.

I want to wish anyone a good day and i will await the replies.

Greetings, Mike

The usual way of achieving this functionality is to store a reference to the current player through a token/cookie and use that to refer to the related row in the database. For example:

  ________players________
  id  |    name    | gold
  25  | "Player 1" |  0

Being the database structure, if I wish to update "Player 1"'s gold count I would take the cookie value $_COOKIE['player_id'] to update the row in the database

<?php

    $player_id = $_COOKIE['player_id'];
    $new_gold = $old_gold + 2;

    $sql = mysqli_connect(HOST,USERNAME,PASSWORD);
    mysqli_select_db(DATABASE,$sql);

    $sql->query("UPDATE `players` SET `gold` = '" . $new_gold . "' WHERE `id` = '" . $player_id . "'");

?>

This poses a number of security concerns but the principle is the same.

I hope this is of some help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.