berry05 Posted December 17, 2008 Share Posted December 17, 2008 say my field is 100 and i subtract 50 from it..how would i do that? i have this code but i know its not right $increment = "UPDATE users SET gold = gold - "50""; mysql_query($increment,$connect); Quote Link to comment https://forums.phpfreaks.com/topic/137455-solved-how-to-subtract-a-field-from-a-number/ Share on other sites More sharing options...
DarkWater Posted December 17, 2008 Share Posted December 17, 2008 UPDATE users SET gold = gold - 50; That will lower EVERYONE'S gold by 50, so you probably want a WHERE clause. Quote Link to comment https://forums.phpfreaks.com/topic/137455-solved-how-to-subtract-a-field-from-a-number/#findComment-718291 Share on other sites More sharing options...
berry05 Posted December 17, 2008 Author Share Posted December 17, 2008 i tried something like this.. UPDATE users WHERE username ='$Username' AND SET gold = gold - 50; and i get error.. Parse error: syntax error, unexpected T_STRING in C:\wamp\www\test\login\hoe.php on line 47 Quote Link to comment https://forums.phpfreaks.com/topic/137455-solved-how-to-subtract-a-field-from-a-number/#findComment-718301 Share on other sites More sharing options...
premiso Posted December 17, 2008 Share Posted December 17, 2008 $increment = "UPDATE users SET gold = (gold - 50) WHERE username = '" . $username . "'"; mysql_query($increment,$connect); Make sure $username is either $Username or $username, be consistent through out the code. Quote Link to comment https://forums.phpfreaks.com/topic/137455-solved-how-to-subtract-a-field-from-a-number/#findComment-718302 Share on other sites More sharing options...
berry05 Posted December 17, 2008 Author Share Posted December 17, 2008 thxs! Quote Link to comment https://forums.phpfreaks.com/topic/137455-solved-how-to-subtract-a-field-from-a-number/#findComment-718306 Share on other sites More sharing options...
twm Posted December 17, 2008 Share Posted December 17, 2008 in my view it is better to use id numbers not usernames. If you set up your id field as the primary and increment, it should not have duplicates no matter what. Quote Link to comment https://forums.phpfreaks.com/topic/137455-solved-how-to-subtract-a-field-from-a-number/#findComment-718308 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.