Jump to content


Photo

Not allowing a user to type a character...*SOLVED*


  • Please log in to reply
6 replies to this topic

#1 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 16 September 2006 - 11:52 PM

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...

$deposit = $_POST['deposit'];

if (eregi('-', $deposit)) {
	echo "You can't deposit a negative amount!";
exit;
}

I also tried this:

$deposit = $_POST['deposit'];

if ($deposit < 0){
    echo "You can't deposit a negative amount!";
exit;
}

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.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 16 September 2006 - 11:56 PM

if ($deposit < 0)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 16 September 2006 - 11:58 PM

Is that not what I already had? It did the same thing...

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 17 September 2006 - 12:01 AM

When I first read your post you hadn't added that second bit. You edited while I was posting.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 17 September 2006 - 12:02 AM

Ah, okay =)

#6 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 17 September 2006 - 12:09 AM

Hmm....this is odd. I just tried this and it is totally ignoring the first IF.

//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'");

}
}


#7 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 17 September 2006 - 12:10 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users