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" ?> Quote Link to comment 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" } ?> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.