Using if(isset($_POST['submit'])) to not display echo when script is open is not working

后端 未结 7 549
走了就别回头了
走了就别回头了 2020-11-28 14:50

I have a little problem with my if(isset($_POST[\'submit\'])) code. What I want is some echos and a table to not appear when the script is open but I do want it

相关标签:
7条回答
  • 2020-11-28 15:02

    You need to give your submit <input> a name or it won't be available using $_POST['submit']:

    <p><input type="submit" value="Submit" name="submit" /></p>
    
    0 讨论(0)
  • 2020-11-28 15:03

    The $_post function need the name value like:

    <input type="submit" value"Submit" name="example">
    

    Call

    $var = strip_tags($_POST['example']);
    if (isset($var)){
        // your code here
    }
    
    0 讨论(0)
  • 2020-11-28 15:06

    You must give a name to your submit button

    <input type="submit" value"Submit" name="login">
    

    Then you can call the button with $_POST['login']

    0 讨论(0)
  • 2020-11-28 15:13

    Another option is to use

    $_SERVER['REQUEST_METHOD'] == 'POST'
    
    0 讨论(0)
  • 2020-11-28 15:14

    You never named your submit button, so as far as the form is concerned it's just an action.

    Either:

    1. Name the submit button (<input type="submit" name="submit" ... />)
    2. Test if (!empty($_POST)) instead to detect when data has been posted.

    Remember that keys in the $_POST superglobal only appear for named input elements. So, unless the element has the name attribute, it won't come through to $_POST (or $_GET/$_REQUEST)

    0 讨论(0)
  • 2020-11-28 15:16

    What you're checking

    if(isset($_POST['submit']))
    

    but there's no variable name called "submit". well i want you to understand why it doesn't works. lets imagine if you give your submit button name delete <input type="submit" value="Submit" name="delete" /> and check if(isset($_POST['delete'])) then it works in this code you didn't give any name to submit button and checking its exist or not with isset(); function so php didn't find any variable like "submit" so its not working now try this :

    <input type="submit" name="submit" value="Submit" />
    
    0 讨论(0)
提交回复
热议问题