SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    317
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    numbers auto being negative

    I have a game that allows you to withdraw/deposit points from your bank. Whenever you go to deposit large amounts of money, such as 999999999999999999999999

    if turns the number into a - number and it gives the user +999999999999999 points.

    Heres some code:

    PHP Code:
    $deposit intval(abs(checkinput($_POST['deposit'])));
    if(!empty(
    $deposit)) {
      if ( !
    ereg("[0-9]+$",$deposit)) {
    echo
    "Error: Do not change the item variable.";
    exit();
    }
    $sel=mysql_query("SELECT * FROM `banks` WHERE `userid` = '$userid2'") or die(mysql_error());
    $mg=mysql_num_rows($sel);
    $gg=mysql_fetch_array($sel);
    $points $gg['points'];
    $collectint $gg['collectint'];

    //Now do deposit
    //Check that user has the amount of fp to deposit

    if($points2 $deposit) {
    $input="You do not have that much $pointsname to deposit.";
    error($input);
    }
    //Take points away
    $fp3 $points2 $deposit;
    $fr=mysql_query("UPDATE `Member` SET `points` = '$fp3' WHERE `ID` = '$userid2'") or die(mysql_error());
    //Add points to bank amount
    $points $points $deposit;
    //Add points to bank
    if($mg == 0) {
    $collectint "No";
    $se=mysql_query("INSERT INTO `banks`(userid, points, collectint) VALUES('" $userid2 "', '" $deposit "', '" $collectint "')") or die(mysql_error());
    }else{ 
    $f=mysql_query("UPDATE `banks` SET `points` = '$points' WHERE `userid` = '$userid2'") or die(mysql_error());
    }
    echo
    "Transaction complete. Go back to <a href='bank.php'> The Bank </a>";
    }

    I'm not too sure why PHP is turning long integers into -'s, so i'm wondering if there is something i need to set in order to make it accept them or a way to code it so that it stops allowing long integers.

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is your bank row set at, INT(value) -- you should cap the value maybe, or is it TINYINT

  3. #3
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    317
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    its set to 255 :X

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    999999999999999999999999 is beyond the max integer limit of pretty much everything. You would be hard to find a way to support that as an actual integer.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably the easiest method is to check the length of the string. If it's longer than a value that could be used, its invalid, and don't use it as an integer.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •