louis_coetzee Posted March 20, 2009 Share Posted March 20, 2009 Notice: Undefined variable: login in C:\wamp\www\www.website.co.za\sub\login.php on line 9 All of the sudden I get this error! never got it before??? What could have happened??? Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/ Share on other sites More sharing options...
Maq Posted March 20, 2009 Share Posted March 20, 2009 Show us line 9 along with some of the surrounding code. Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-789873 Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 Means a variable is not set that all. Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-789875 Share on other sites More sharing options...
.josh Posted March 20, 2009 Share Posted March 20, 2009 lots of reasons that could happen. You could have upgraded to a new/diff php version that has error reporting set to show notices. You could have added script somewhere that turns it on. You could have deleted a var someone or reordered something to where that variable is not defined at that point in time (and error reporting set to that level). It's just a notice, saying that the variable has not been declared. You can make it go away be declaring it before using it, turning error reporting off on notices, or just ignoring it (because php allows you to use variables on the fly like that). Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-789878 Share on other sites More sharing options...
louis_coetzee Posted March 20, 2009 Author Share Posted March 20, 2009 <form action="" method="post" name="login"> <link href="style1.css" rel="stylesheet" type="text/css"> <p><strong>Login</strong> <br>Please enter your username and password to login to your account.</p> <p><img src="images/line.gif" width="588" height="1"></p> <!-- Check if fields are filled out --> <!-- Check if fields are filled out --> <?php extract($_REQUEST); [b]line 9 ----[/b] if ($login == 'login') { echo '<div class="paddedtext" id="errorbox">'; ///////////////// extract($_POST); if ($username == '') { echo 'Please enter your username.'; }else{ if ($password == '') { echo 'Please enter your password.'; }else{ $dbhost = 'localhost'; $dbuser = 'whateva'; What do I edit in php.ini to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-789888 Share on other sites More sharing options...
Ninjakreborn Posted March 21, 2009 Share Posted March 21, 2009 You can eliminate the errors by testing isset before you test if the variable is empty. <?php if (isset($variable) && $variable != '') { // Do something. } ?> This way it tests if it's set...if it's not then it stops running. If it is set then it moves onto the next statement. Checking if something == '' or != '' will throw an undefined error if the variable is not defined. That's why you should always test if it's set before anything else. Edit: Also try putting a more descriptive title when posting in the forums. It will increase the chances of getting help. Edit Part 2: I also do not advise using extract on $_POST. Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-790015 Share on other sites More sharing options...
bluejay002 Posted March 21, 2009 Share Posted March 21, 2009 Also, you might also want to avoid using variables that were not currently declared - though this maybe unnecessary - or better try businessman's suggestion if what I suggested is not an option. Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-790020 Share on other sites More sharing options...
Ninjakreborn Posted March 21, 2009 Share Posted March 21, 2009 If you want to turn off error reporting: http://tinyurl.com/ccx7kj Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-790023 Share on other sites More sharing options...
DeanWhitehouse Posted March 21, 2009 Share Posted March 21, 2009 Do not ignore the errors, or turn them off (while developing), fix them, it will make you a better coder and make the code better. All you need to do is make sure that all the variables are defined before using them. E.g. if(!isset($Var)) $Var = ""; Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-790226 Share on other sites More sharing options...
louis_coetzee Posted March 21, 2009 Author Share Posted March 21, 2009 Thanks a lot, have been checking if they are set, and this is solving the problem, just the hassle of doing it throughout the entire website. Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-790235 Share on other sites More sharing options...
DeanWhitehouse Posted March 21, 2009 Share Posted March 21, 2009 you don't need to do that for all variables, but if you have messy code and/or cannot tell if the variable has been set then do that. Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-790236 Share on other sites More sharing options...
wildteen88 Posted March 21, 2009 Share Posted March 21, 2009 Thanks a lot, have been checking if they are set, and this is solving the problem, just the hassle of doing it throughout the entire website. Im not surprised if you have to do it to all variables judging by the code you posted above which I have quoted: <?php extract($_REQUEST); [b]line 9 ----[/b] if ($login == 'login') { echo '<div class="paddedtext" id="errorbox">'; ///////////////// extract($_POST); if ($username == '') { echo 'Please enter your username.'; }else{ if ($password == '') { echo 'Please enter your password.'; }else{ $dbhost = 'localhost'; $dbuser = 'whateva'; What do I edit in php.ini to fix this? extracting all superglobal variables is just as bad as enabling register_globals. What so hard in typing $_POST['username'] over $username? Taking short cuts like this just causes more problems in the long run and can make your code vulnerable to attack. Quote Link to comment https://forums.phpfreaks.com/topic/150402-what-the-hell-is-going-on/#findComment-790243 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.