PHP upload - Why isset($_POST['submit']) is always FALSE

后端 未结 5 1376
执念已碎
执念已碎 2021-01-05 06:08

I have the following code sample upload3.php:



PHP Form Upload



相关标签:
5条回答
  • 2021-01-05 06:21
    <input type='submit' value='Upload' />
    

    should be

    <input type='submit' value='Upload' name='subname'/>
    

    and that subname should be in $_POST[' ']

    it will look like

    if (isset($_POST['subname']))
    {
        echo "isset submit";
    }
    else 
    {
        echo "NOT isset submit";
    }
    
    0 讨论(0)
  • 2021-01-05 06:22

    Because you don't have any form element whose name property is submit.

    Try to use var_dump($_POST) to see the keys that are defined.

    Notice that files are an exception; they're not included in $_POST; they're stored in the filesystem and they're metadata (location, name, etc) is in the $_FILES superglobal.

    0 讨论(0)
  • 2021-01-05 06:23

    You do not have your submit button named:
    Change

    <input type='submit' value='Upload' />
    

    To:

    <input type='submit' value='Upload' name="submit"/>
    
    0 讨论(0)
  • 2021-01-05 06:24

    Try looking at the REQUEST_METHOD and see if it's POST. It's a little bit nicer.

    0 讨论(0)
  • 2021-01-05 06:36

    Two things:

    You'll want to try array_key_exists instead of isset when using arrays. PHP can have some hinky behavior when using isset on an array element.

    http://www.php.net/manual/en/function.array-key-exists.php

    if (array_key_exists('submit', $_POST)) { }

    Second, you need a name attribute on your button ( "name='submit'" )

    0 讨论(0)
提交回复
热议问题