webguy262 Posted December 21, 2011 Share Posted December 21, 2011 this does not work for me... $category=mysql_real_escape_string($_GET['category']); if (is_int($category)) { i echo out $category and confirm it is an integer and yet the if statement does not fire what am i missing? Quote Link to comment https://forums.phpfreaks.com/topic/253603-is_int-useage/ Share on other sites More sharing options...
AyKay47 Posted December 21, 2011 Share Posted December 21, 2011 you are retrieving this from either a query string or a form value correct? If so, the number is passed as a numeric string, not an integer. you can either cast the numeric string into an int before using is_int(), or you can use is_numeric() instead. Quote Link to comment https://forums.phpfreaks.com/topic/253603-is_int-useage/#findComment-1300056 Share on other sites More sharing options...
kney Posted December 21, 2011 Share Posted December 21, 2011 Shouldn't you use is_numeric? $category=mysql_real_escape_string($_GET['category']); if (is_numeric($category)) { Edit: What AyKay47 says Quote Link to comment https://forums.phpfreaks.com/topic/253603-is_int-useage/#findComment-1300057 Share on other sites More sharing options...
AyKay47 Posted December 21, 2011 Share Posted December 21, 2011 I normally cast numeric string values right off the bat when I am transferring data. Makes for neater and easier code.. $category= (int)$_GET['category']; if(is_int($category)) { } Quote Link to comment https://forums.phpfreaks.com/topic/253603-is_int-useage/#findComment-1300059 Share on other sites More sharing options...
ManiacDan Posted December 21, 2011 Share Posted December 21, 2011 $category= (int)$_GET['category']; if(is_int($category)) { } This code is unnecessary. Of course a variable you just cast as an int will be an int. You should check to make sure it's not zero. If zero is a valid value for $category, you shouldn't cast at all and use is_numeric. Quote Link to comment https://forums.phpfreaks.com/topic/253603-is_int-useage/#findComment-1300075 Share on other sites More sharing options...
AyKay47 Posted December 21, 2011 Share Posted December 21, 2011 $category= (int)$_GET['category']; if(is_int($category)) { } This code is unnecessary. Of course a variable you just cast as an int will be an int. You should check to make sure it's not zero. If zero is a valid value for $category, you shouldn't cast at all and use is_numeric. true that would definitely be overkill. Quote Link to comment https://forums.phpfreaks.com/topic/253603-is_int-useage/#findComment-1300083 Share on other sites More sharing options...
webguy262 Posted December 21, 2011 Author Share Posted December 21, 2011 thanks for all the info! Quote Link to comment https://forums.phpfreaks.com/topic/253603-is_int-useage/#findComment-1300087 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.