bford21 Posted February 9, 2010 Share Posted February 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191444-mysql-update-and-where-clause-help/ Share on other sites More sharing options...
trq Posted February 9, 2010 Share Posted February 9, 2010 Are you getting any error? You have a syntax error in your statement. Notice the strange ' char ? $result = mysql_query("UPDATE members SET gold= $temp_gold WHERE member_id = '{$_SESSION['MEMBER_ID']}'"); Quote Link to comment https://forums.phpfreaks.com/topic/191444-mysql-update-and-where-clause-help/#findComment-1009280 Share on other sites More sharing options...
Mchl Posted February 9, 2010 Share Posted February 9, 2010 And you can actually do $result = mysql_query("UPDATE members SET gold= gold+100 WHERE member_id = '{$_SESSION['MEMBER_ID']}'"); Quote Link to comment https://forums.phpfreaks.com/topic/191444-mysql-update-and-where-clause-help/#findComment-1009295 Share on other sites More sharing options...
bford21 Posted February 10, 2010 Author Share Posted February 10, 2010 Hey guys thanks for your help. The problem ended up being that strange ' char. I think I copied and pasted that code from somewhere so I didn't write it myself. Sorry about now being so descriptive. I'm sure I'll have more questions to ask in the upcoming days. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/191444-mysql-update-and-where-clause-help/#findComment-1009849 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.