onthespot Posted July 15, 2009 Share Posted July 15, 2009 Any ideas why this doesnt work? Or could someone explain where I put this better? $news=mysql_real_escape_string($_GET['news']); if(!is_int($news)){ echo 'This piece of news does not exist. Back to <a href="news.php">News</a>'; exit(); }else{ } This returns everything as not being an integer. So even when the news=17, the message still displays. Any ideas? Link to comment https://forums.phpfreaks.com/topic/166080-solved-if_int/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 15, 2009 Share Posted July 15, 2009 is_int tests whether the type of a variable is integer. It does not test if the contents of a variable is an integer. Use is_numeric or cast $news are as an integer. Link to comment https://forums.phpfreaks.com/topic/166080-solved-if_int/#findComment-875859 Share on other sites More sharing options...
onthespot Posted July 15, 2009 Author Share Posted July 15, 2009 Works a treat, where would I ever use is_int then? Link to comment https://forums.phpfreaks.com/topic/166080-solved-if_int/#findComment-875860 Share on other sites More sharing options...
PFMaBiSmAd Posted July 15, 2009 Share Posted July 15, 2009 If you wanted to test if the type of a variable is integer, i.e. not a string or not an array or not an object. While it is true that a variable that is of type integer can only hold an integer, a variable that is a string can hold strings that have meaning when treated as an integer. $_GET variables are by definition always strings and mysql_real_escape_string() only returns a sting (no matter what 'value' you give it), so $news in the posted code is a string that might or might not contain something that can be treated as an integer. Link to comment https://forums.phpfreaks.com/topic/166080-solved-if_int/#findComment-875863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.