busby Posted February 27, 2011 Share Posted February 27, 2011 ok..ive done this a million times..i have a working example here and i copied it and amended it for this new project but for some reason i cant get a form to post data to another page. this is the error message i get Notice: Undefined index: username in C:\wamp\www\uni\fyp\site\mobile\login.php on line 16 Notice: Undefined index: password in C:\wamp\www\uni\fyp\site\mobile\login.php on line 17 here is my form code: <form method="post" action="login.php"> <table align="center" cellpadding="0" cellspacing="0"> <tr> <td style="vertical-align:top;">Username: </td><td><input type="text" name="username" value="" /></td> </tr> <tr> <td style="vertical-align:top;">Password: </td><td><input type="password" name="password" value="" /><br /><input type="submit" id="submit" value="Login" /></td> </tr> </table> </form> and here is the code within the login.php where the form should post to $username = $_POST['username']; $password = $_POST['password']; // Help protect against MySQL injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); // Selecting data from database where correct username and password are found $sql="SELECT * FROM customer WHERE username='$username' and password='$password'"; $result=mysql_query($sql) or die(mysql_error()); i cant see anything wrong..been looking for hours...please please help me Quote Link to comment Share on other sites More sharing options...
Krash Posted February 27, 2011 Share Posted February 27, 2011 1. - echo the $username and $password to confirm that form input is getting to login.php 2. - Read this - http://php.net/manual/en/function.mysql-real-escape-string.php Quote Link to comment Share on other sites More sharing options...
busby Posted February 27, 2011 Author Share Posted February 27, 2011 ive already tried that...it just produces the same error. ive just stumbled upon something very strange. i have 1 record in my database with the data in the username field as "kevin" and the data in the password field as "busby". when i try to login by typing a bunch of randum letters...those values go to login.php and i can echo them out. but if i type in the correct username and password...it doesnt post through to login.php any suggestions? Quote Link to comment Share on other sites More sharing options...
Krash Posted February 28, 2011 Share Posted February 28, 2011 The problem has to be in login.php, not the form code. Start with the last line in the script and rem out one line at a time until login.php echos the input. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 28, 2011 Share Posted February 28, 2011 Is the form & the code that processes the data in the same file? If so, you need to check to see if the form was submitted before blindly using the data. Ken 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.