Jump to content

Archived

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

pocobueno1388

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

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.

Share this post


Link to post
Share on other sites
When I first read your post you hadn't added that second bit. You edited while I was posting.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.