Glese Posted December 11, 2011 Share Posted December 11, 2011 <?php $user_name = 'bazarr'; $user_password = '*******'; if($_POST['user_name'] != $user_name || $_POST['user_password'] != $user_password) { ?> <h3>The Login</h3> <form method="post" action=""> <input type="text" name="user_name" /> <input type="password" name="user_password" /> <input type="submit" name="blog_creation_login_submit" value="Submit" /> </form> <?php } else { ?> <h3>The Article</h3> With the above script I am getting following notice: Notice: Undefined index: user_name It is regarding the user name variable, my question is how to solve this one and avoid the notice? Quote Link to comment https://forums.phpfreaks.com/topic/252959-notice-about-not-defined-index-with-login-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2011 Share Posted December 11, 2011 The same way someone suggested in one of your previous threads - http://www.phpfreaks.com/forums/index.php?topic=349042.msg1646845#msg1646845 Quote Link to comment https://forums.phpfreaks.com/topic/252959-notice-about-not-defined-index-with-login-form/#findComment-1296948 Share on other sites More sharing options...
KevinM1 Posted December 11, 2011 Share Posted December 11, 2011 You avoid the notice by checking to see if the variable exists. Index, in this context, means array index. The array in question is $_POST. It's telling you that $_POST['user_name'] doesn't exist; or, more specifically, 'user_name' is an undefined index because it wasn't set during the POST because whatever form input it's supposed to come from was empty. So, you need to ensure that the variable exists by checking either isset or empty before attempting to use it in another way. Quote Link to comment https://forums.phpfreaks.com/topic/252959-notice-about-not-defined-index-with-login-form/#findComment-1296949 Share on other sites More sharing options...
Glese Posted December 11, 2011 Author Share Posted December 11, 2011 I got it to work. Thanks kevin for the explanation, this part of PHP is confusing me a bit. Quote Link to comment https://forums.phpfreaks.com/topic/252959-notice-about-not-defined-index-with-login-form/#findComment-1296953 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.