Jump to content

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


pocobueno1388

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.