Forum Moderators: coopster

Message Too Old, No Replies

How to find if submitted number is a negative

         

dkin

3:08 am on Apr 26, 2005 (gmt 0)

10+ Year Member



I have a form that my users fill out and I just found this kink.

does anyone know how to find if a number is negative without using the < 0 approach?

I am using that approach right now and it is not working.

This is what Ive done

if ($str ¦¦ $sta ¦¦ $agi ¦¦ $dex < 0)
{
echo 'You can not insert negative numbers please <a href="account.php">click here</a> to return to your account.';
echo $str.''.$sta.''.$agi.''.$dex;
exit;
}

but regardless of what I put in it continues to say its negative, even if all 4 numbers are positive.

jd01

3:16 am on Apr 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi dkin,

Not sure if it will work for your specific situation, but have you thought about getting the absolute value of the numbers entered?

EG $variable = abs($original_number)

If you just want positive numbers this should be effective.

Hope this helps.

Justin

ACJavascript

3:16 am on Apr 26, 2005 (gmt 0)

10+ Year Member



When addressing more then 1 variable in a single IF statement you need to address them individualy.

Example:
if ($str <0 ¦¦ $sta<0 ¦¦ $agi<0 ¦¦ $dex < 0)

Give that a go.

dkin

3:23 am on Apr 26, 2005 (gmt 0)

10+ Year Member



that worked ACJavascript ty