Jump to content

[resolved] Bank Not Working


kirbyweb

Recommended Posts

  • Replies 55
  • Created
  • Last Reply
$username = mysql_fetch_array($query);$last = $username['lastupdate']; //timestamp from db$extraTime = time() - $last;$money = floor($extraTime / 60);if ($money<500){if ($money > 0) {	//lets update users table	mysql_query("UPDATE `castle wars users` SET money=money+$money WHERE id= '$username[id]'") or die(mysql_error());}echo 'user\'s money:'. ((int)$username['money']+(int)$money) .'money.';}else echo 'user\'s money: 500';	//lets update users table	mysql_query("UPDATE `castle wars users` SET lastupdate=lastupdate+$extraTime WHERE id= '$username[id]'") or die(mysql_error());?>

Yeah now, even when it is 498 it still updates the money.

Link to comment
Share on other sites

Yeah, look at the if statements. You're telling it to update the money when the money to be added (not the user's money, but the money to add) is between 0 and 500:

if ($money<500){if ($money > 0) {

You're also not making sure it stops at 500, as long as the money to add is between 0 and 500 you add it. You don't check to see if the money to add plus the current amount would be more than 500. You also always print that the user has 500 without checking what it actually is, the database could say 600 but you're printing that the user has 500.

Link to comment
Share on other sites

why don't you try it? Work out the logic with us if you have to. I understand this may be new to you, but it is basic stuff, and you should really be trying to at least attempt it on your own first. Sometimes it is easier to write out the logic step by step; telling the computer instructions as if you were telling it to a person. Work it out and when you think it makes sense, start converting each line to code. Put a bunch of print statements in your code to track how your code is executing. Maybe that will help.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...