Notice: Undefined index: test in /home/sendmail/public_html/test2.php on line 2

Discussion in 'PHP' started by Marketer456, Apr 5, 2009.

  1. #1
    SO here is the thing i have one file called test.php which has this code in it

    <form action="test2.php" method="post">
    <input type="text" name="test">
    <input type="submit">
    </form>


    then it submits info to test2 which has this code in it

    <?php
    echo $_POST["test"];
    ?>

    Now can you please guys tell me what the hell in the world am i doing wrong that its is giving me the error

    Notice: Undefined index: test in /home/sendmail/public_html/test2.php on line 2

    Please help,
    - Avo
     
    Marketer456, Apr 5, 2009 IP
  2. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #2
    It means the variable you are trying to use doesn't exist.

    Wrap the $_POST['text'] part in a if-statement.

    
    <form action="test2.php" method="post">
    <input type="text" name="test">
    <input type="submit">
    </form>
    
    <?php
    if (isset($_POST["test"])) {
    echo $_POST["test"];
    }
    ?>
    PHP:
    or

    
    <form action="test2.php" method="post">
    <input type="text" name="test">
    <input type="submit" name="submit">
    </form>
    
    <?php
    if (isset($_POST["submit"])) {
    echo $_POST["test"];
    }
    ?>
    PHP:
    - ads2help
     
    ads2help, Apr 5, 2009 IP
  3. kakek

    kakek Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Notice is not an error. you can just ignore it, default php setting disable notice reporting.

    to disable notice add this command at top of the script (usually index.php or config)
    error_reporting(E_ALL ^ E_NOTICE);
     
    kakek, Apr 5, 2009 IP
  4. Stylesofts

    Stylesofts Peon

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hello,

    Well try to use this script and see what happens.

    
    <form action="test2.php" method="post">
    <input type="text" name="test" id="test">
    <input type="submit" name="rePost" id="rePost" value="Submit" />
    <input type="hidden" name="rePost" id="rePost" />
    </form>
    
    <?php
    error_reporting(0);
    if (isset($_POST["rePost"]))
    {
    echo $_POST["test"];
    }?>
    
    Code (markup):
     
    Stylesofts, Apr 5, 2009 IP
  5. Marketer456

    Marketer456 Peon

    Messages:
    120
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you guys =]
     
    Marketer456, Apr 6, 2009 IP