TottoBennington Posted January 25, 2012 Share Posted January 25, 2012 Notice: Undefined index: username in C:\wamp\www\LogInSystem\login.php on line 2 Notice: Undefined index: password in C:\wamp\www\LogInSystem\login.php on line 3 Help me to change this error <?php $username = $_POST['username']; ERROR IS IN THIS LINE $password = $_POST['password']; ERROR IS IN THIS LINE if ($username&&$password){ $connect = mysql_connect ("localhost", "root","") or die ("could not connect"); mysql_select_db ("login") or die ("could not find db"); } else { die ("Please enter username and password!");} ?> Quote Link to comment https://forums.phpfreaks.com/topic/255774-notice-undefined-index-php-error/ Share on other sites More sharing options...
AyKay47 Posted January 25, 2012 Share Posted January 25, 2012 holy big text batman.. you are receiving these "notices" (they aren't errors) because you are attempting to call on $_POST values that do not exist upon page load. if(isset($_POST['username']) && isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['password']; } Quote Link to comment https://forums.phpfreaks.com/topic/255774-notice-undefined-index-php-error/#findComment-1311148 Share on other sites More sharing options...
Drongo_III Posted January 25, 2012 Share Posted January 25, 2012 check if it's set first? i.e. if(isset($_POST['password'], $_POST['username'])){ $username = $_POST['username']; $password = $_POST['password']; } else { Do whatever........ } Quote Link to comment https://forums.phpfreaks.com/topic/255774-notice-undefined-index-php-error/#findComment-1311150 Share on other sites More sharing options...
mwaleedgul Posted May 20, 2012 Share Posted May 20, 2012 Please help me I have exhausted now to find out the solution for this. I am new and learning php. I am facing this error. ( ! ) Notice: Undefined index: password in C:\wamp\www\login.php on line 7 Call Stack # Time Memory Function Location 1 0.0015 374152 {main}( ) ..\login.php:0 Please enter the username and password ............................................................... My Form code is...... <html> <form action="login.php" method="POST"> <p><input type="text" name="username"></p> <p><input type="password" name="passsword"></p> <p><input type="submit" name="submit" value="login"></p> </form> </html> and my login.php code is..... <?php session_start(); $username=$_POST['username']; $password=$_POST['password']; if ($username&&$password) { $connect = mysql_connect('localhost','root','') or die ("Couldn't connect to database"); mysql_select_db("alaqsatr_2374") or die ("Couldn't find database"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows($query); if($numrows !=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&$password==$dbpassword) { echo "Login successful. <a href='membersarea.php'> Click here to enter the members area"; $_SESSION['username']=$dbusername; } else echo "Incorrect password"; } else die("That username doesn't exist."); } else die("Please enter the username and password"); ?> Please reply me my email is mwaleedgul@yahoo.com . many thanks Quote Link to comment https://forums.phpfreaks.com/topic/255774-notice-undefined-index-php-error/#findComment-1347056 Share on other sites More sharing options...
Drongo_III Posted June 6, 2012 Share Posted June 6, 2012 Hello Your problem looks to be on your form. You have named the field "passsword" - note the incorrect spelling of password (you have added three S's). The php script is then looking for 'password' - with the correct spelling. This is why you are getting undefined index. Your form is posting "passsword" but your php script is looking for "password" in the post array. Hope that fixes it! Drongo Quote Link to comment https://forums.phpfreaks.com/topic/255774-notice-undefined-index-php-error/#findComment-1351594 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.