ballouta Posted December 3, 2008 Share Posted December 3, 2008 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 More sharing options...
balistic Posted December 3, 2008 Share Posted December 3, 2008 is negative credits allowed, or should they always be positive? Link to comment https://forums.phpfreaks.com/topic/135327-solved-integer-validation-no-signs/#findComment-704844 Share on other sites More sharing options...
ballouta Posted December 3, 2008 Author Share Posted December 3, 2008 it is always positive Link to comment https://forums.phpfreaks.com/topic/135327-solved-integer-validation-no-signs/#findComment-704851 Share on other sites More sharing options...
shatner Posted December 3, 2008 Share Posted December 3, 2008 if ($newcredits > 0){ $query = " UPDATE `rescus` SET `credits` = credits-$newcredits WHERE `customer` = '" . $_SESSION['username'] . "' "; } Link to comment https://forums.phpfreaks.com/topic/135327-solved-integer-validation-no-signs/#findComment-704852 Share on other sites More sharing options...
balistic Posted December 3, 2008 Share Posted December 3, 2008 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 Link to comment https://forums.phpfreaks.com/topic/135327-solved-integer-validation-no-signs/#findComment-704856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.