markvaughn2006 Posted September 12, 2009 Share Posted September 12, 2009 Hi, you guys have really helped me out!! I'm trying to update a users "gold" but I don't want them to be able to hit refresh and keep adding gold. Also this is what I have now mysql_query("UPDATE users_tbl SET gold = '100' WHERE user_name = '$_SESSION[myusername]' "); but obviously this sets "gold" to 100 it doesn't add 100 to "gold", how would I go about doing that? Thanks again guys!! Quote Link to comment Share on other sites More sharing options...
pneudralics Posted September 12, 2009 Share Posted September 12, 2009 You can try reading the gold from the user first then adding 100 to what's read and then update it with the new count. For the refresh you can probably set a timer after they click submit for gold. Quote Link to comment Share on other sites More sharing options...
markvaughn2006 Posted September 12, 2009 Author Share Posted September 12, 2009 is there an ADD command? or would I just store their gold value in a variable ($gold) and then make their "gold" = $gold + '100' or something like that?? Thanks! Quote Link to comment Share on other sites More sharing options...
pneudralics Posted September 12, 2009 Share Posted September 12, 2009 I don't know of any, but when I did something like what you were doing thats how I did it. I would make a database where I can edit the amount of points easily from an admin panel. Then I would just read their points and add my set points to theirs. Quote Link to comment Share on other sites More sharing options...
markvaughn2006 Posted September 12, 2009 Author Share Posted September 12, 2009 so you just updated it manually? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 12, 2009 Share Posted September 12, 2009 why not "gold = gold + 100"? Quote Link to comment Share on other sites More sharing options...
markvaughn2006 Posted September 12, 2009 Author Share Posted September 12, 2009 PARTIALLY SOLVED :you are guys are great, but still have the problem that if you hit refresh it adds 100 gold every time, any idea how to prevent this? $result = mysql_query("SELECT * FROM users_tbl WHERE user_name='$_SESSION[myusername]'") or die(mysql_error()); $row = mysql_fetch_array( $result ); // Print out the contents of each row into a table $gold = $row['gold'] + '100'; mysql_query("UPDATE users_tbl SET gold = '$gold' WHERE user_name = '$_SESSION[myusername]' "); Quote Link to comment Share on other sites More sharing options...
fenway Posted September 12, 2009 Share Posted September 12, 2009 Again, you can do the same in mysql... usually the easiest way around this is to add to the where clause the current value of 'gold'. 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.