N0L1m1t5 Posted July 21, 2011 Share Posted July 21, 2011 I am creating a login page for a web and i keep getting the error posted below: Notice: Undefined index: username in C:\xampp\htdocs\login.php on line 26 Notice: Undefined index: password in C:\xampp\htdocs\login.php on line 27 Incorrect password This is the code i have listed in my login.php document : <?php if( isset($_POST['submit']) && $_POST['Log in']) session_start(); $username = $_POST ['username']; $password = $_POST ['password']; if ($username&&$password) { $connect = mysql_connect ("localhost","root","") or die("Couldn't Connect"); mysql_select_db("database") or die ("Couldn't find db"); $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 "You're in!<a href='member.php'>Click here to enter the member page.</a>"; $_SESSION['username']=$username; } else echo "Incorrect password"; } else die("That user doesn't exist!"); } else die("Please enter a username and a password!"); ?> Can anyone help me please?? Link to comment https://forums.phpfreaks.com/topic/242497-can-anyone-help-me-with-this-basic-code/ Share on other sites More sharing options...
teynon Posted July 21, 2011 Share Posted July 21, 2011 Let's see your form. Link to comment https://forums.phpfreaks.com/topic/242497-can-anyone-help-me-with-this-basic-code/#findComment-1245443 Share on other sites More sharing options...
N0L1m1t5 Posted July 21, 2011 Author Share Posted July 21, 2011 My first page only has the basic features so far: (posted below) <html> <body> <form action = 'login.php' method = 'POST'> Username: <input type='text' name = 'username'><br> Password: <input type = 'password' name = 'password'><br> <input type = 'submit' value = 'Log in'> </body> </html> But i keep getting that same error Link to comment https://forums.phpfreaks.com/topic/242497-can-anyone-help-me-with-this-basic-code/#findComment-1245446 Share on other sites More sharing options...
Maknib Posted July 21, 2011 Share Posted July 21, 2011 are you sure there is a $row['username'] ? Link to comment https://forums.phpfreaks.com/topic/242497-can-anyone-help-me-with-this-basic-code/#findComment-1245454 Share on other sites More sharing options...
N0L1m1t5 Posted July 21, 2011 Author Share Posted July 21, 2011 so what exactly does $row['username'] do and mean? is there a replacement code I could enter and test? thanks Link to comment https://forums.phpfreaks.com/topic/242497-can-anyone-help-me-with-this-basic-code/#findComment-1245459 Share on other sites More sharing options...
Maknib Posted July 21, 2011 Share Posted July 21, 2011 Quote so what exactly does $row['username'] do and mean? is there a replacement code I could enter and test? thanks While a row of data exists, put that row in $row as an associative array. If you're expecting just one row, no need to use a loop which im guessing that there wont be more than 1 person with the same username. try changing this $numrows= mysql_num_rows($query); if ($numrows!=0) { while($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } to this $numrows= mysql_num_rows($query); if ($numrows!=0) { $row = mysql_fetch_assoc($query); print_r($row); { } Link to comment https://forums.phpfreaks.com/topic/242497-can-anyone-help-me-with-this-basic-code/#findComment-1245461 Share on other sites More sharing options...
dilum Posted July 21, 2011 Share Posted July 21, 2011 Put you code inside curly brackets : if( isset($_POST['submit']) && $_POST['Log in']) { // you code....... } Link to comment https://forums.phpfreaks.com/topic/242497-can-anyone-help-me-with-this-basic-code/#findComment-1245477 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.