排球图书馆应要求提供错误500

时间:2019-10-23 15:46:13

标签: java php android-volley

我有以下代码将数据保存到mysql数据库中;

    private void save(final String orderId, final String client, final String name, final String Seller, final String amount, final String quantity, final double longi, final double lat, final String location, final ProgressDialog progressDialog) {
    String URL_ORDER = "https://foodfuzz.co.ke/foodfuzzbackend/market/orders/order.php";
    StringRequest orderStringRequest = new StringRequest(Request.Method.POST, URL_ORDER,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject orderObject = new JSONObject(response);
                        String orderSuccess = orderObject.getString("success");
                        if(orderSuccess.equals("1")){
                            Toast.makeText(CheckOutActivity.this,"Order Placed Successfully " , Toast.LENGTH_SHORT).show();
                            pay.setVisibility(View.GONE);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        progressDialog.dismiss();
                        Toast.makeText(CheckOutActivity.this,"Unable to place order " + e.toString(), Toast.LENGTH_SHORT).show();
                        pay.setEnabled(true);
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    progressDialog.dismiss();
                    Toast.makeText(CheckOutActivity.this,"Error placing order " + error.toString(), Toast.LENGTH_SHORT).show();
                    pay.setEnabled(true);
                }
            }){
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put("orderId",orderId);
            params.put("name", name);
            params.put("client", client);
            params.put("seller", Seller);
            params.put("amount", amount);
            params.put("quantity",quantity);
            params.put("longitude",String.valueOf(longi));
            params.put("latitude",String.valueOf(lat));
            params.put("location",location);
            return params;
        }
    };
    RequestQueue orderRequestQueue = Volley.newRequestQueue(this);
    orderRequestQueue.add(orderStringRequest);

}

我的问题是,发出发布请求时收到错误代码500。以下是在logcat上记录的实际错误

BasicNetwork.performRequest: Unexpected response code 500 for https://foodfuzz.co.ke/foodfuzzbackend/market/orders/order.php

这是服务器上指定网址上的php代码

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    require_once '../db/connector.php';
    $orderId = mysqli_real_escape_string($conn, $_POST['orderId']);
    $client = mysqli_real_escape_string($conn, $_POST['client']);
    $product = mysqli_real_escape_string($conn, $_POST['name']);
    $seller = mysqli_real_escape_string($conn, $_POST['seller']);
    $amount = mysqli_real_escape_string($conn, $_POST['amount']);
    $quantity = mysqli_real_escape_string($conn, $_POST['quantity']);
    $longi = mysqli_real_escape_string($conn, $_POST['longitude']);
    $lati = mysqli_real_escape_string($conn, $_POST['latitude']);
    $loc = mysqli_real_escape_string($conn, $_post['location']);
    $status = 1;

    $sql = "INSERT INTO tbl_orders (orderid, client, product, seller, amount, quantity, longitude, latitude, deliveryloc, status) VALUES ('$orderId', '$client', '$product', '$seller', '$amount', '$quantity', '$longi', '$lati', '$loc', '$status')";

    if (mysqli_query($conn, $sql)) {
        $result["success"] = "1";
        $result["message"] = "success";

        echo json_encode($result);
        mysqli_close($conn);
    } else {

        $result["success"] = "0";
        $result["message"] = "error";

        echo json_encode($result);
        mysqli_close($conn);
    }
}

该代码适用于邮递员,没有任何错误。我怎么可能做错了

1 个答案:

答案 0 :(得分:1)

此错误通常是由您的代码中的错误引起的,首先最好检查您的php脚本是否无错误,以及其他代码是否正确。就我而言,帖子数据与表格列不匹配。