Required Field(s) missing result

后端 未结 2 926
别那么骄傲
别那么骄傲 2021-01-25 05:32

I\'ll just keep this question short. What is wrong with my php code, it keeps outputting 0 or Required Field(s) is missing. Here\'s the code



        
相关标签:
2条回答
  • 2021-01-25 05:46

    Your error says it all. Since you get to the } else { ... } bit, it means isset($_POST['id']) && isset($_POST['status_id']) is false.

    In other words, your form is either:

    • not using POST, but GET. In that case add method="post" to your <form> tag. (actually, POST is default behaviour, so if this is the case, you probably have to remove or change method="GET" from the form tag)
    • and/or your form does not contain input fields with name="id" and/or name="status_id"

    The updated question adds Android code. Hence this update:

    I doubt that jsonParser.makeHttpRequest actually posts a form encoded json string. It more then likely will just POST json data to the webserver. PHP's $_POST will not automatically be filled with this data, since it only handles form encoded data.

    You probably need to read this data from stdIn.

    Try:

    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $rawPostData = file_get_contents("php://input");
        $postData = (array)json_decode($rawPostData);
    }
    

    And then use $postData where you otherwise would use $_POST

    0 讨论(0)
  • 2021-01-25 05:56

    Just debug the $_POST['id'] and $_POST['status_id']. Before this line.

    if (isset($_POST['id']) && isset($_POST['status_id'])) {
    

    you will find answer automatically. Hopefully one of two post variables is not set. For debug use print_r($_POST);

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