0

我正在开发一个应用程序,该应用程序允许员工请求休假该帖子并从现有的 MySQL 数据库中读取。但是我很难弄清楚在整个代码部分(PHP,JAVA)中要修复什么。任何专家可以告诉我如何解决这个问题吗?

这是我目前收到的错误消息

D/Create Response(284): {"message":"Required field(s) is missing","success":0}

请求 PHP API

<?php
// array for JSON response
$response = array();

// check for the fields
if (isset($_POST['title']) && isset($_POST['request_date']) && isset($_POST['reqEndDate']) && isset($_POST['reason']) && isset($_POST['requestor']) && isset($_POST['status']) && isset($_POST['submitDate']) && isset($_POST['explanation']) && isset($_POST['hours']) && isset($_POST['id'])) {

    $title = $_POST["request_title"];
    $date = $_POST["request_date"];
    $eDate = $_POST["reqEndDate"];
    $reason = $_POST["reason"];
    $requestor = $_POST["requestor"];
    $status = $_POST["status"]; 
    $dateSubmitted = $_POST["submitDate"];
    $explanation = $_POST["explanation"];
    $numhours = $_POST["hours"];
    $empid = $_POST['id'];


    // mysql inserting a new row
    $result = mysql_query("INSERT INTO requests(request_title, request_date, reqEndDate, reason, requestor, status, submitDate, explanation, hours, empid) 
                            VALUES('$title', '$date', '$eDate', '$reason', '$requestor', '$status', '$dateSubmitted', '$explanation', '$numhours', '$empid')");


} else {

    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    echo json_encode($response);
}
?>

请求 JAVA 类

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("request_title", title));
            params.add(new BasicNameValuePair("request_date", date));
            params.add(new BasicNameValuePair("reqEndDate", eDate));
            params.add(new BasicNameValuePair("hours", hours));
            params.add(new BasicNameValuePair("reason", reason));
            params.add(new BasicNameValuePair("explanation", explanation));

            // getting JSON Object
            // Note that create request url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_request,
                    "POST", params);

            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully created request
                    Intent i = new Intent(getApplicationContext(), AllRequestsActivity.class);
                    startActivity(i);

                    // closing this screen
                    finish();
                } else {
                    // failed to create request
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }



    }
}
4

3 回答 3

2

我认为错误消息非常具有描述性。

ifPHP代码中的第一个。

在请求中包含所有必填字段。

于 2012-06-14T13:49:54.350 回答
0

PHP 脚本正在查找 $_POST 中设置的 10 个变量,但您的 Java 类仅在“参数”中发送 6 个。

于 2012-06-14T13:51:14.257 回答
0

以下“如果”中提到的字段之一在您的 POST 请求中不存在

if (isset($_POST['title']) && isset($_POST['request_date']) && isset($_POST['reqEndDate']) && isset($_POST['reason']) && isset($_POST['requestor']) && isset($_POST['status']) && isset($_POST['submitDate']) && isset($_POST['explanation']) && isset($_POST['hours']) && isset($_POST['id'])) {
于 2012-06-14T13:51:37.370 回答