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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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