pocobueno1388 Posted September 16, 2006 Share Posted September 16, 2006 I have a bank script where users can deposit fake game money into their bank. The problem is I don't know how to restict them from depositing negative amounts. So I would like to give the user an error if they submit a number with a negative sign (-). Here is the code that I thought would work...[code]$deposit = $_POST['deposit'];if (eregi('-', $deposit)) { echo "You can't deposit a negative amount!";exit;}[/code]I also tried this:[code]$deposit = $_POST['deposit'];if ($deposit < 0){ echo "You can't deposit a negative amount!";exit;}[/code]They both just seem to ignore everything, as if I didn't put the code there in the first place.Any help is appreciated XD Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 16, 2006 Share Posted September 16, 2006 if ($deposit < 0) Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted September 16, 2006 Author Share Posted September 16, 2006 Is that not what I already had? It did the same thing... Quote Link to comment Share on other sites More sharing options...
Barand Posted September 17, 2006 Share Posted September 17, 2006 When I first read your post you hadn't added that second bit. You edited while I was posting. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted September 17, 2006 Author Share Posted September 17, 2006 Ah, okay =) Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted September 17, 2006 Author Share Posted September 17, 2006 Hmm....this is odd. I just tried this and it is totally ignoring the first IF.[code]//If they deposit==========================================if ($deposit == deposit){if ($deposit < 0){ echo "You can't deposit a negative amount!";exit;} else if (!is_numeric($amount)){ echo "<table width='80%' bgcolor='49614A'><td align='center' bgcolor='788D7A'><b>You must enter a number, do not include a $ sign.</b></td></table>";exit; } else if ($amount > $row[money]){ echo "<table width='80%' bgcolor='49614A'><td align='center' bgcolor='788D7A'><b>You don't have that much money to deposit!</b></td></table>";exit;} else {echo "<table width='80%' bgcolor='49614A'><td align='center' bgcolor='788D7A'><b>Successfully deposited $$amount</b></td></table>";mysql_query("UPDATE players SET bank=bank+$amount, money=money-$amount WHERE playerID='$sid'");}}[/code] Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted September 17, 2006 Author Share Posted September 17, 2006 Ughh...I am sorry. This whole time I have been using $deposit instead of $amount as my variable. I solved the problem though. Thanks anyways. 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.