newBieUser0829 newBieUser0829 - 1 month ago 8x
MySQL Question

How to Insert Data to Mysql Database using Volley

I am trying to insert data to mysql database using volley, but it always response as error, I'm stuck and cant go further to my project. I can't find what causing it not to execute the my PHP codes. I also checked my PHP code using PostMan and it is working well. I'm now trying to insert some test data to it but still no luck. I hope you can shine some light in me and provide me some help. Thank you.


Button confirmOrder = (Button) findViewById(;
confirmOrder.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {

final int a = 1;
final String b = "Beth";
final int c = 1;
final int d = 3;
final int e = 1;
final String f = "Bert";

final String URL = "";

StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
public void onResponse(String response) {
if(response.contains("success")) {
Toast.makeText(getApplicationContext(), "success", Toast.LENGTH_SHORT).show();
}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("table_id", String.valueOf(a));
params.put("cust_name", b);
params.put("item_id", String.valueOf(c));
params.put("quantity", String.valueOf(d));
params.put("status_id", String.valueOf(e));
params.put("username", f);
return params;





if(isset($_POST['table_id']) && isset($_POST['cust_name']) &&
isset($_POST['item_id']) && isset($_POST['quantity']) && isset($_POST['status_id'])
&& isset($_POST['username'])){
$tableid = $_POST['table_id'];
$custname = $_POST['cust_name'];
$itemid = $_POST['item_id'];
$quantity = $_POST['quantity'];
$statusid = $_POST['status_id'];
$username = $_POST['username'];

$query = "INSERT INTO tbl_order(table_id,cust_name,item_id,quantity,status_id,username)
VALUES ('$tableid', '$custname', '$itemid', '$quantity', '$statusid', '$username')";

$result = mysqli_query($con, $query);

if($result > 0){
echo "success";
echo "failed";



The line - final String URL = "";"; you misspelled http