Php recylerview购物车上的项目可以全部输入数据库

Php recylerview购物车上的项目可以全部输入数据库,php,android,database,android-arrayadapter,Php,Android,Database,Android Arrayadapter,嗨,我在通过数据库插入数据时遇到了一些问题,我只在recylerview上发送了一项数据 这是我的cart和php代码,我正在使用它 komen.php <?php require_once 'index.php';if ($_SERVER['REQUEST_METHOD'] =='POST'){ $nama = $_POST['nama']; $komen = $_POST['komen']; $sql = "INSERT INTO komen_table (nama, komen)

嗨,我在通过数据库插入数据时遇到了一些问题,我只在recylerview上发送了一项数据

这是我的cart和php代码,我正在使用它

komen.php

<?php require_once 'index.php';if ($_SERVER['REQUEST_METHOD'] =='POST'){

$nama = $_POST['nama'];
$komen = $_POST['komen'];

$sql = "INSERT INTO komen_table (nama, komen) VALUES ('$nama', '$komen')";

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);
}}?>
数据库上的值可以是多个但相同的项,就像循环相同的项一样,但总是进入捕获,这将是错误。我需要解决它,知道哪一个是我的错 谢谢

public class KeranjangFragment extends Fragment {
private EditText product,prices;
TextView total;
Button btnpesan;
String tr;
private static String URL_pesan ="http://mercyshopper.000webhostapp.com/product.php";

public KeranjangFragment() {
}

public static List<Product> example = new ArrayList<>();
ProductAdapter madapter;
public String title;
public int productImage;
public double price;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View krnjg =inflater.inflate(R.layout.fragment_keranjang,container,false);

    RecyclerView rec = krnjg.findViewById(R.id.rc1);
    LinearLayoutManager aw1 =new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
    rec.setLayoutManager(aw1);


    total = krnjg.findViewById(R.id.vtotal);
    madapter = new ProductAdapter(getContext(), example, getLayoutInflater(), total);
    rec.setAdapter(madapter);
    product = krnjg.findViewById(R.id.barang);
    prices = krnjg.findViewById(R.id.hrga);

    btnpesan = krnjg.findViewById(R.id.btnpsn);
    Locale locale = new Locale("in","ID");

    NumberFormat formatrupiah = NumberFormat.getCurrencyInstance(locale);
    total.setText(formatrupiah.format(madapter.getTotalPrice()));

    btnpesan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            placeorder();
            final String mtotal = total.getText().toString();
            Intent intent = new Intent(getActivity(), CheckoutActivity.class);
            intent.putExtra("total",mtotal);
            startActivity(intent);
        }
    });

    return krnjg;
}
 private void placeorder() {
    final ProgressDialog pDial = new ProgressDialog(getActivity());
    pDial.setMessage("Loading...");
    pDial.show();

    final String product = madapter.getproduct();
    final String prices = madapter.getprice();
    StringRequest stringRequest = new StringRequest(Request.Method.POST, URL_pesan,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        String success = jsonObject.getString("success");
                        if (success.equals("1")){
                            Intent intent = new Intent(getActivity(), CheckoutActivity.class);
                            intent.putExtra("product", product);
                            intent.putExtra("price", prices);

                            Toast.makeText(getActivity(), "Data Tersimpan", Toast.LENGTH_SHORT).show();
                            pDial.dismiss();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                        Toast.makeText(getActivity(), "Gagal Menyimpan", Toast.LENGTH_SHORT).show();
                        pDial.dismiss();
                    }
                }
            },new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getActivity(), "Tidak Dapat Menyimpan", Toast.LENGTH_SHORT).show();
            pDial.dismiss();
        }
    })
    {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("product",product);
            params.put("price",prices);
            return params;
        }
    };
    RequestQueue requestQueue= Volley.newRequestQueue(getActivity());
    requestQueue.add(stringRequest);

}
Product prod = new Product; prod.setTitle(jsonObject.getString(product)); example.add(prod);