shortysbest Posted April 7, 2010 Share Posted April 7, 2010 Im building a login forum and i am getting the notices Notice: Undefined index: username in C:....login.php on line 2 Notice: Undefined index: password in C:\....login.php on line 3 I can't figure out what's going on. any help would be thankful <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"> </form> </body> </html> <?php $username = $_POST['username']; //t his is line 2 $password = $_POST['password']; // this is line 3 if ($username&&$password) { $connect = mysql_connect("localhost","root","") or die ("couldn't connect!"); mysql_select_db("phplogin") or die("couldn't find db"); } else die("please enter a username and a password"); ?> Quote Link to comment Share on other sites More sharing options...
DavidAM Posted April 7, 2010 Share Posted April 7, 2010 When the page is first requested, the $_POST[] elements do not exist. They are only there after the user submits the form. Wrap the login stuff in an if statement: if(isset($_POST['username']){ ... } so the code is not executed until the form is submitted. Quote Link to comment 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.