SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Wales
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Notice: Undefined index: PHP 5 What causes this?

    I realise it's just a notice but this suggests to me that I should sort out the problem, notice or not. This notice originates from a form which submits to a file which processes the fields and then sends.

    First off then, these are the notices;

    Notice: Undefined index: advice in D:\***\thanks.php on line 10

    Notice: Undefined index: ukeurope in D:\***\thanks.php on line 30

    Notice: Undefined index: usacanada in D:\***\thanks.php on line 31

    Notice: Undefined index: other in D:\***\thanks.php on line 32

    And here is the corresponding code in the processing page;

    10 if ( $_POST['advice']) {

    30 $ukeurope = $_POST['ukeurope'];

    31 $usacanada = $_POST['usacanada'];

    32 $other = $_POST['other'];


    I've read somewhere that it's due to me not doing this:

    $advice = $_POST['advice'];

    Would this be the case do you think?

    Hope someone can help with this as I'd really like to do this correctly!

    Rob

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are referencing $_POST['advice'] when $_POST['advice'] isn't set.
    Try doing if(isset($_POST['advice'])) { .... }

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Wales
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah yes, I see what you mean, logical really! I'll make the changes you suggested. Thanks Mark, and thanks for your extremely quick reply!

    Rob

  4. #4
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello guys i have seached the forum for this undefined index error but my case seems different as I ran the following form:

    target_path = "uploads/";
    $target_path = $target_path.basename($_FILES['uploadedFile']['name']);

    if(move_uploaded_file($_FILES['uploadedFile']['tmp_name'], $target_path)){

    echo "The file". basename($_FILES['uploadedFile']['name']). "has been uploaded";
    }
    else{
    echo "There was an error uploading the file, please try again!";
    }
    ?>
    The error: line 23 is the highlited line above.
    Notice: Undefined index: uploadedFile in C:\wamp\www\saterisk\uploadmanager.php on line 23.

    Could someone please help? Thanks

  5. #5
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try like this::
    $target_path = $target_path.basename($HTTP_POST_FILES['uploadedFile']['name']);

  6. #6
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tried the suggestion and had the error below:

    Notice: Undefined variable: HTTP_POST_FILES in C:\wamp\www\saterisk\uploadmanager.php on line 23
    Call Stack
    # Time Memory Function Location
    1 0.0013 376352 {main}( ) ..\uploadmanager.php:0

    Guido, I have noted your point.

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,491
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Do a print_r of $_FILES and see what it contains.

    And please, next time don't bump a 4 year old thread to ask your question. Create a new thread, and if needed link to the old one.

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    HTTP_POST_FILES was deprecated in php 4.1.x
    use $_FILES instead

    edit

    Just reread your original post where you are indeed using $_FILES!

    OK, Check that in your form your file input field is called uploadedFile
    ie
    <input type="file" name="uploadedFile" />
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ View Post
    HTTP_POST_FILES was deprecated in php 4.1.x
    use $_FILES instead

    edit

    Just reread your original post where you are indeed using $_FILES!

    OK, Check that in your form your file input field is called uploadedFile
    ie
    <input type="file" name="uploadedFile" />
    many thanks. my input file name was "uploadedfile" while i was using "uploadedFile" in my php script. Apologies for bothering you for this mistake of mine. Maybe i needed a third eye.

  10. #10
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    HTTP_POST_FILES is no longer valid, IIRC.

    Check out the information (array keys) available to you in the $_FILES superglobal in the manual

    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    dont apologise, we have all done it at some time or another (and still do!)
    Glad you got it sorted
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

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