Php_Ghost Posted May 29, 2010 Share Posted May 29, 2010 I need a small help over this code. I am getting $ID variable not defined. So i dont what code should I used to prevent this error. If id variable not exist then it should go to sorry. it is going but also showing that msg. Any idea how to fix that. <?php $ID = $_GET['ID']; if ($ID) //if ID has some value then it should on screen. echo $ID; else echo "Sorry" ?> Link to comment https://forums.phpfreaks.com/topic/203271-small-code-help/ Share on other sites More sharing options...
-Karl- Posted May 29, 2010 Share Posted May 29, 2010 <?php $ID = $_GET['ID']; if (!empty($ID)) { //if ID has some value then it should on screen. echo $ID; } else { echo "Sorry" } ?> Link to comment https://forums.phpfreaks.com/topic/203271-small-code-help/#findComment-1064998 Share on other sites More sharing options...
Php_Ghost Posted May 30, 2010 Author Share Posted May 30, 2010 Thank You Brother Karl. i will keep in mind next time. Link to comment https://forums.phpfreaks.com/topic/203271-small-code-help/#findComment-1065228 Share on other sites More sharing options...
kenrbnsn Posted May 30, 2010 Share Posted May 30, 2010 Be careful when using the empty function. It will return a false positive if the value of the variable that you're testing is 0 (zero). Ken Link to comment https://forums.phpfreaks.com/topic/203271-small-code-help/#findComment-1065233 Share on other sites More sharing options...
ignace Posted May 30, 2010 Share Posted May 30, 2010 $ID = array_key_exists('ID', $_GET) ? intval($_GET['ID']) : -1; if (1 > $ID) {//invalid Link to comment https://forums.phpfreaks.com/topic/203271-small-code-help/#findComment-1065302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.