Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2012
    Posts
    44
    Tokens
    273

    Default PHP Help: Undefined Index

    I'm currently using XAMPP and practising some PHP, however I've stumbled across a small problem.

    I won't post all of my code as it's extremely long, so I'll post a section of it. We're dealing with buttons and performing actions after a button has been pressed.

    PHP Code:
    <input type="submit" name="submit" />

    <?php
        
    if($_POST['submit'])
        {
            echo 
    'You\'ve pressed the submit button!';
        }
    ?>
    This piece of code throws this error, Notice: Undefined index: submit in C:\xampp\htdocs\test.php on line 4 (Line 4 is this code - if($_POST['submit'])). Does anyone know the problem with this code? When I click on the submit button, it doesn't echo out "You've pressed the submit button!".

    Help would be appreciated.
    Last edited by Tuts; 08-06-2012 at 11:49 AM.

  2. #2
    Join Date
    Jun 2005
    Location
    Nottingham
    Posts
    5,277
    Tokens
    75

    Latest Awards:

    Default

    Undefined index means you're trying to evaluate a variable, or in this case an element of an array, that doesn't exist at that point in the run of the code. Also, please say that button is in <form> tags.
    VR|46

  3. #3
    Join Date
    May 2005
    Location
    /etc/passwd
    Posts
    19,110
    Tokens
    1,139

    Latest Awards:

    Default

    Post the rest of your code. $_POST['submit'] isn't set.
    Quote Originally Posted by Chippiewill View Post
    e-rebel forum moderator
    :8

  4. #4
    Join Date
    May 2007
    Posts
    10,481
    Tokens
    3,140

    Latest Awards:

    Default

    you may may want to use if(isset($_POST['submit'])) instead
    Chippiewill.


  5. #5
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    $_POST is an array, 'submit' is the index that you're trying to pull out of the array. You're trying to get and check it when it's not there.

Posting Permissions

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