Jump to content

[SOLVED] if_int


onthespot

Recommended Posts

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

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

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.