Volley 库根据 post 请求给出错误 500

Volley Library giving error 500 on post request

我使用以下代码将数据保存到 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);

}

我的问题是在发出 post 请求时收到错误代码 500。以下是logcat

上记录的实际错误
BasicNetwork.performRequest: Unexpected response code 500 for https://foodfuzz.co.ke/foodfuzzbackend/market/orders/order.php

这是服务器上的 php 代码 url

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

代码在 postman 上运行,没有任何错误。我做错了什么

此错误通常是由您的代码错误引起的,首先最好检查您的 php 脚本和其他代码是否没有错误。在我的例子中,post 数据与 table 列不匹配。