Jump to content
MakeWebGames

Question about type column bank & money


rjddev

Recommended Posts

I'm facing a small problem when I withdraw/deposit money.

For example, I have $98,007,285,155 money in my bank or on hand, I want to deposit/withdraw it in one time, but it deposits/withdraws only $2,147,483,647 max.

I have both columns on bigint(250).

Is there another type I should use in the database for this so players are able to deposit/withdraw their cash in one click?

Link to comment
Share on other sites

Doesn't sound like the database is the issue, but rather the PHP.

If you are using something like...

 

$amount = abs(@intval($_POST['amount']));

 

The intval will make it "int value", so you will have the same problem as the database running with int(11) -- it maxes at 2,147,483,647

Try using float... or a better economic model.

Link to comment
Share on other sites

Doesn't sound like the database is the issue, but rather the PHP.

If you are using something like...

 

$amount = abs(@intval($_POST['amount']));

 

The intval will make it "int value", so you will have the same problem as the database running with int(11) -- it maxes at 2,147,483,647

Try using float... or a better economic model.

Thank you for the help, I have now removed the (int) from $amount and done it like this.

 

if(isset($_POST['deposit']) != "") {
   $amount = mysql_real_escape_string($_POST['damount']);

   $notallowed = array('$', '-', '_', '+', '=', '<', '>', ',');
   $amount = str_replace($notallowed, "", $amount);

  if(!preg_match('#^[0-9]+$#', $amount)) {
$message = "Please enter a valid amount.";
  } 
  else if($amount < 1) {
      $message = "Please enter a valid amount.";
  }
  else if($amount <= $player->money) {
      $message = "You have deposited " . prettynum($amount);
      $newbank = $amount + $player->bank;
      $newmoney = $player->money - $amount;

      $result = mysql_query("UPDATE `grpgusers` SET `bank` = '$newbank', `money` = '$newmoney' WHERE `id` = '".$player->id."'");
  }
}

if(isset($_POST['withdraw']) != "") {
   $amount = mysql_real_escape_string($_POST['wamount']);

   $notallowed = array('$', '-', '_', '+', '=', '<', '>', ',');
   $amount = str_replace($notallowed, "", $amount);

   if(!preg_match('#^[0-9]+$#', $amount)) {
$message = "Please enter a valid amount.";
   }    
   else if($amount > $player->bank) {
       $message = "You do not have that much money in your bank";
   }
   else if($amount < 1) {
       $message = "Please enter a valid amount.";
   }
   else if($amount <= $player->bank && $amount > 0) {
       $newbank = $player->bank - $amount;
       $newmoney = $player->money + $amount;

       $result = mysql_query("UPDATE `grpgusers` SET `bank` = '$newbank', `money` = '$newmoney' WHERE `id` = '".$player->id."'");

       $message = "You have withdrawn " . prettynum($amount);
   }
}

if(isset($message)) {
   echo Message($message);
}

 

This seems to be secure and working correct.

Thank you :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...