Jump to content

[SOLVED] Integer Validation no signs


ballouta

Recommended Posts

Hi

i have the vartiable credits posted from an html form.

after submission, this query runs:

 

$query = " UPDATE `rescus` SET `credits` = credits-$newcredits WHERE `customer` = '" . $_SESSION['username'] . "' ";

 

If someone enter in teh html form -5 for credits, it will make wrong result.

How do i validate the credits entered so it doesn't contain +, -,* or / ?

 

thank you

 

Link to comment
https://forums.phpfreaks.com/topic/135327-solved-integer-validation-no-signs/
Share on other sites

nah, a better way to do it would be to just run the value of credits through the absolute function :)

 

$query = " UPDATE `rescus` SET `credits` = ".abs($credits)."-$newcredits WHERE `customer` = '" . $_SESSION['username'] . "' ";

 

that way if it is positive or a negative number it will come back as a positive

 

http://au.php.net/abs

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.