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. Link to comment https://forums.phpfreaks.com/topic/21016-not-allowing-a-user-to-type-a-charactersolved/ Share on other sites More sharing options...
Barand Posted September 16, 2006 Share Posted September 16, 2006 if ($deposit < 0) Link to comment https://forums.phpfreaks.com/topic/21016-not-allowing-a-user-to-type-a-charactersolved/#findComment-93284 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... Link to comment https://forums.phpfreaks.com/topic/21016-not-allowing-a-user-to-type-a-charactersolved/#findComment-93287 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. Link to comment https://forums.phpfreaks.com/topic/21016-not-allowing-a-user-to-type-a-charactersolved/#findComment-93288 Share on other sites More sharing options...
pocobueno1388 Posted September 17, 2006 Author Share Posted September 17, 2006 Ah, okay =) Link to comment https://forums.phpfreaks.com/topic/21016-not-allowing-a-user-to-type-a-charactersolved/#findComment-93292 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] Link to comment https://forums.phpfreaks.com/topic/21016-not-allowing-a-user-to-type-a-charactersolved/#findComment-93293 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. Link to comment https://forums.phpfreaks.com/topic/21016-not-allowing-a-user-to-type-a-charactersolved/#findComment-93295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.