0

I'm working on an application which allows employees to Request time off that post and read from an existing MySQL database. But I'm having a little trouble figuring out what to fix in this entire section of codes(PHP, JAVA). Could any expert show me how this can be fixed please?

It's the error message I'm currently getting

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

Request 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);
}
?>

Request JAVA CLASS

            // 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;
        }



    }
}

3 Answers 3

2

I think the error message is quite descriptive.

The first if in PHP code.

Include all required fields in request.

Sign up to request clarification or add additional context in comments.

Comments

0

the PHP script is looking for 10 variables set in $_POST, but your Java class is only sending 6 in "params".

Comments

0

One of the fields mentioned in the "if" below doesn't exist in your POST request

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'])) {

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.