Hey guys! I am new to the forums and am looking for some help. First off I am using 000webhost.com as a host and it is running PHP 5.2. and MySQL 5.0.81-community.
I am fairly new to PHP and completely new to MySQL. I am self taught and normally can figure things out myself but I am really puzzled on this one.
I am in the process of creating a text based game. The problem comes when I have the user go to "the mines" and "mine" for gold. Right now I have it set so every time they mine they get 100 gold. I want the users gold to go up by 100 obviously and I want it reflected in both my database and the members profile.
I assume to do this I would use the MySQL UPDATE function. This is what I have been doing but I cant seem to figure out how to get only that users gold to go up. I did some research and found out about the WHERE clause and have tried to use it to identify the user but I cant seem to work it out.
This is what I have so far:
I connect to the the MySQL server, and select the database then I wrote this line of code:
$temp_gold = $_SESSION['MEMBER_GOLD'] + 100;
$result = mysql_query("UPDATE members SET gold= $temp_gold WHERE member_id = ’{$_SESSION['MEMBER_ID']}'");
$_SESSION['MEMBER_GOLD'] is the members gold when the user first logged in and $_SESSION['MEMBER_ID'] is the users ID.
To me the statement makes perfect sense. Update the table "members" and set "gold" equal to "$temp_gold" which is the gold before + 100. Obviously this is wrong though and I would really appreciate your guys help! Thanks in advance.