newbie :a very simple $_POST is giving me an error

Discussion in 'PHP' started by friendlymentor, Jul 16, 2011.

  1. #1
    Well, its the first time i am writing up my own php instead of editing someone else's.

    Here is the very simple code where I am asking user to input a password and then just echo it.

    <form action="index.php" method="POST">
    	Please enter your password: <br>
    	<input type="text" name="password" /> <br>
    	<input type="submit" value="Submit" />
    </form>
    
    <?php
    $password= $_POST['password'];
    echo $password;
    
    ?>
    PHP:

    And, I am getting following error:
    Notice: Undefined index: password in C:\wamp\www\md5\index.php on line 8

    I have read everything I possibly could but still cant figure out whats wrong?
     
    friendlymentor, Jul 16, 2011 IP
  2. oxyzenwebmedia

    oxyzenwebmedia Peon

    Messages:
    18
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    TRY this
    <?php
    if(isset($_POST['password']))
    {
       $password= $_POST['password'];
       echo $password;
    }
    
    ?>
    PHP:
     
    oxyzenwebmedia, Jul 16, 2011 IP
  3. sinha.sidhi

    sinha.sidhi Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?php
    if(isset($_POST['password']))
    {
    $password= $_POST['password'];
    echo $password;
    }

    ?>
     
    sinha.sidhi, Jul 19, 2011 IP
  4. CrostE

    CrostE Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #4
    If you don't want the action to happend before you have clicked the button you must use isset.
    if(isset($_POST['buttonName']))
    {
    // Action 
    }
    
    Code (markup):
     
    CrostE, Jul 19, 2011 IP
  5. suryawl

    suryawl Peon

    Messages:
    54
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #5
    use isset() will do the trick. or you can set variable error_reporting(E_ALL ^ E_NOTICE); before everything
     
    suryawl, Jul 22, 2011 IP