Php Android使用截取将ArrayList数据发送到MySQL

Php Android使用截取将ArrayList数据发送到MySQL,php,android,mysqli,android-volley,Php,Android,Mysqli,Android Volley,我试图通过使用PHP作为桥接器将ArrayList数据发送到MySQL,为了实现同样的目的,我使用Volley实现了代码 以下是我写的: private void uploadToDatabase() { for (int i = 0; i < imageList.size(); i++) { image_file = imageList.get(i).getImageFileName(); } StringRequest stringReque

我试图通过使用PHP作为桥接器将ArrayList数据发送到MySQL,为了实现同样的目的,我使用Volley实现了代码

以下是我写的:

private void uploadToDatabase() {

    for (int i = 0; i < imageList.size(); i++) {
        image_file = imageList.get(i).getImageFileName();
    }

    StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
            response -> {
                try {
                    JSONArray itemArray = new JSONObject(response).getJSONArray("images");
                    for (int i = 0; i < itemArray.length(); i++) {
                        String value = itemArray.getString(i);
                        Toast.makeText(getApplicationContext(), "Result:" + value + "\n", Toast.LENGTH_LONG).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }, error -> Toast.makeText(UploadActivity.this,error.toString(),Toast.LENGTH_LONG)) {

        @Override
        protected Map<String,String> getParams() {

            Map<String,String> params = new HashMap<>();

            params.put("image_file", image_file);

            return params;
        }
    };

    RequestQueue requestQueue = Volley.newRequestQueue(UploadActivity.this);
    requestQueue.add(stringRequest);

}

变量
image\u file
的类型是什么?仅字符串@atishagrawala根据您的代码,
image\u file=imageList.get(i).getImageFileName()此行将使用列表imageList中的最后一个文件名更新图像_文件。你认为这是正确的逻辑吗?我正试图上传列表中所有可用的文件名。。。但主要的问题是并没有一个文件名被上传到表中。根据我的理解,你们做得不对。您需要创建一个包含所有文件名的JSON数组,然后将其发布到服务器。另外,我认为imageList变量已经是一个列表,您可以直接将其转换为JSON数组并将其传递给params。
<?php 

    $DB_HOST = "localhost";
    $DB_USER = "";
    $DB_PASS = "";
    $DB_NAME = "primary_db";

 $conn = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);

 ?>
<?php 

    include "db_config.php";
    $conn = new mysqli($DB_HOST,$DB_USER,$DB_PASS,$DB_NAME);

    if($conn)
    {

        $json = $_POST['images'];
        $json_array = json_decode($json,true);

        for($i=0; $i<count($json_array);$i++)
        {
            $image_file = $json_array[$i]["image_file"];

            $sql = "INSERT INTO images(image_file) values('$image_file')";

            if(mysqli_query($conn,$sql))
            {
                echo json_encode(array('response'=>'uploaded successfully'));
            }

        }

    }

    else
    {
        echo json_encode(array('response'=>'connection Failed'));
    }

mysqli_close($conn);

?>
    for (int i = 0; i < imageList.size(); i++) {
        image_file = imageList.get(i).getImageFileName();
    }
    final String image_file = imageDataList.get(0).getImageFileName();