burtybob Posted October 12, 2007 Share Posted October 12, 2007 I have a piece of code sayin $staff1 = $_REQUEST['staff1']; // also tried with $_GET and $_POST but neither worked for me if (isset($staff1)) { echo "hello"; } And i am not 'setting' the variable so why is it echoing the hello (i am going to turn the actual true statement into a usefull thing but i thought echoing something i would be able to see if it is working) Please can anyone help as i have spent the last week looking thorugh this code to make sure nothing is passed to the variable to be able to set it. Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/ Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 But you are setting the variable. You are doing it in the preceding line. Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/#findComment-367996 Share on other sites More sharing options...
burtybob Posted October 12, 2007 Author Share Posted October 12, 2007 yh i know but there isnt anydata going into it maybe i should be using if (empty(variable)){ execute code } ????? Thanks for the fast reply! Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/#findComment-367998 Share on other sites More sharing options...
snowman15 Posted October 12, 2007 Share Posted October 12, 2007 yes thats correct, I think you are setting the value to null which is actually setting the variable. yet null is still an empty value. i think? Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/#findComment-368003 Share on other sites More sharing options...
burtybob Posted October 12, 2007 Author Share Posted October 12, 2007 OOPs Programming lol!!!! (very bad pun) Now i am checking to see if its empty and im using same code as before but instead of isset() im using empty () and even when its got data it still echos hello!!! any ideas? I even tried manually giveing the variable a value in the code and still it echos!!! Please? Grr i even tell the code to echo if its empty and it actually echos a value! Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/#findComment-368007 Share on other sites More sharing options...
ingeva Posted October 12, 2007 Share Posted October 12, 2007 Why don't you echo the var itself and see what it contains? $staff1 = $_REQUEST['staff1']; echo $staff1; You may also use echo int($staff1); etc. Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/#findComment-368014 Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 For debugging, try this. <?php $staff1 = $_REQUEST['staff1']; // also tried with $_GET and $_POST but neither worked for me print_r($staff1); if (isset($staff1)) { echo "hello"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/#findComment-368016 Share on other sites More sharing options...
burtybob Posted October 12, 2007 Author Share Posted October 12, 2007 Why don't you echo the var itself and see what it contains? $staff1 = $_REQUEST['staff1']; echo $staff1; You may also use echo int($staff1); etc. If you read my post i did try this also mmmvomit i have tried the isset() method and as someone pointed out the variable does set! Even if it is $staff='' still becomes 'set' Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/#findComment-368047 Share on other sites More sharing options...
MmmVomit Posted October 12, 2007 Share Posted October 12, 2007 You missed the line of code I added. print_r($staff1); Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/#findComment-368051 Share on other sites More sharing options...
burtybob Posted October 13, 2007 Author Share Posted October 13, 2007 You missed the line of code I added. print_r($staff1); Sorry you are right i did miss that piece of code and it now doesnt echo when the variable isnt set, thank you can i please ask what the print_r actually does because in the php manual it says its to do with arrays is this true? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/72973-isset-nope-not-setting-so/#findComment-368591 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.