Frezzwar Posted April 10, 2011 Share Posted April 10, 2011 Hi. I'm still very new to this forum, so i may be asking this the wrong way. I'm working on a project, but i keep running into the same wall. Whenever i try to load a page with a variable i named on another page, i get an error telling me that it does not know that variable. But how do i make it check for the variable before using it? Example of my code (i only show the first part, as it is the only one relevant): <html><body> <?php session_start(); if($_SESSION['username']); { $username = $_SESSION['username']; As you can see i have tried to deal with it using an if statement, but i still get the error. I bet there is a very simple way to do this, but i cant see it right now. Quote Link to comment https://forums.phpfreaks.com/topic/233261-checking-for-undefined-variables/ Share on other sites More sharing options...
php.ajax.coder Posted April 10, 2011 Share Posted April 10, 2011 You need to use the isset function <?php session_start(); if(isset($_SESSION['username'])); { $username = $_SESSION['username']; Quote Link to comment https://forums.phpfreaks.com/topic/233261-checking-for-undefined-variables/#findComment-1199615 Share on other sites More sharing options...
Frezzwar Posted April 10, 2011 Author Share Posted April 10, 2011 I bet you think you are so smart! Well... It seems you are. It seems to be working. Thank you for the help! Quote Link to comment https://forums.phpfreaks.com/topic/233261-checking-for-undefined-variables/#findComment-1199617 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.