php isset($ _ post)无效? [关闭]

I am working with this issue since last few hours and also searched the related questions on stack overflow. I have a simple html form

<form name="user_verification" action="action.php" method="POST">
 Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit" name="submit" value="submit">
</form>

and here is the php script in action.php file

if(isset($_POST['submit'])) 
{
echo 'yes';
}else{
echo 'no';
}

It always display "no". I tested my php script using this

 if(1==1) 
    {
    echo 'yes';
    }else{
    echo 'no';
    }

In this case, it displays "yes". This means that problem is with isset($_POST['submit']) function but I can't find out the solution. please help in this regard. thanks

For robustness its best to check the method against the request.
This is a simple example of a form processor validating a post request.

if ('POST' === $_SERVER['REQUEST_METHOD']) {
    if (!isset($_POST['required_data'])) {
        http_send_status(400);
        exit;
    }

    echo 'OK';
}

You will still need to check with isset against the fields you require.

Maybe somewhere $_POST values are emptied/unseted. This may be due to php configuration or as security measure (i.e. http://php.net/manual/en/ini.core.php#ini.enable-post-data-reading). You may check $_REQUEST and also check if you can get $_GET values (method of form is get).

The above code will only display the submitted values if the submit button was clicked.

isset( ). This is an inbuilt function that checks if a variable has been set or not. In between the round brackets, you type what you want isset( ) to check. For us, this is $_POST['Submit']. If the user just refreshed the page, then no value will be set for the Submit button. If the user did click the Submit button, then PHP will automatically return a value

$var = '';

// This will evaluate to TRUE so the text will be printed.
if (isset($var)) {
    echo "This var is set so I will print.";
}

You may also use the var_dump(isset()); // TRUE to output the return value of isset().

Your code is correct, it's working for me. See this for more info.

In index.php

<form name="user_verification" action="action.php" method="POST">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit" name="submit" value="submit">
</form>

in action.php

<?php if(isset($_POST['submit'])) 
 {
 echo 'yes';
 }else{
  echo 'no';
 } ?>

Your code is correct.

It works only when you submit the form.

So, unless you submit the form, it will always print no.