Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    USB
    USB is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Notice: Undefined index: password

    hi, what is wrong with this code? i'm getting this notice "Notice: Undefined index: password in C:\wamp\www\login.php on line 6"

    PHP Code:
    <?php
    include('config.php');

    if(
    $_SERVER['REQUEST_METHOD'] =='POST') {
        
    $username mysql_real_escape_string($_POST['username']);
        
    $password mysql_real_escape_string(md5($_POST['password']));
        
        
        
    $query mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
        
    $query_rows mysql_num_rows($query);
        
      if(
    $query_rows 0) {
          echo(
    "Succesfull login!");
          
        
    session_start();
        
    $_SESSION['login'] ="1";
      }
      else
      {
          echo(
    "Bad login!");
      }
    }
    ?>
    <html>
        <head>
            <title>Login</title>
        </head>
        <body>
            <form action="login.php" method="post"/>
            Username: <input type="text" name="username" /><br />
            Password: <input type="password" nanme="password" /><br />
            <input type="submit" value="Login" />
         </form>
         </body>
    </html>
    //Max

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,421
    Thanks
    62
    Thanked 535 Times in 522 Posts
    Somewhere near the top of your script, you need to do this:
    var_dump($_POST);

    That will show you what is being sent.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    USB
    USB is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts
    it seems like its not sending the password.

    array
    'username' => string 'Max' (length=3)

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,421
    Thanks
    62
    Thanked 535 Times in 522 Posts
    Well there you go then. The password isn't being sent for some reason. Do you type text into it?
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,421
    Thanks
    62
    Thanked 535 Times in 522 Posts
    Quote Originally Posted by USB View Post
    hi, what is wrong with this code? i'm getting this notice "Notice: Undefined index: password in C:\wamp\www\login.php on line 6"

    PHP Code:
            Password: <input type="password" nanme="password" /><br /> 

    There you go, you've spelt 'name' incorrectly.

    It's 'name' NOT 'nanme'
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •