Adamhumbug Posted February 10, 2020 Share Posted February 10, 2020 I have a message bar that when a page reloads, a message appears at the top of the screen. I feed the message with session variables that are set at the end of the action (submission for example) When the page reloads the message displays and then unsets the session variables. The issue is when the page first loads (when it has never run an action) and gives me the Notice: Undefined index: message. My question is, how can i handle the session being blank when the page first loads and thus not get the notice. Quote Link to comment Share on other sites More sharing options...
Adamhumbug Posted February 10, 2020 Author Share Posted February 10, 2020 I think i have answered my own question about 10 seconds after posting this. if(!empty($_SESSION['message'])){ doesnt seem to generate the same message that if($_SESSION['message'] !=''){ did Thanks anyway Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 10, 2020 Share Posted February 10, 2020 A clearer test could be to use the "isset" function: if (isset($_SESSION['message'])) echo $_SESSION['message']; Quote Link to comment Share on other sites More sharing options...
Adamhumbug Posted February 11, 2020 Author Share Posted February 11, 2020 17 hours ago, ginerjm said: A clearer test could be to use the "isset" function: if (isset($_SESSION['message'])) echo $_SESSION['message']; Thanks for this. 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.