In my program I have ListView
of rooms(only available are shown). Tapping on one of items results in showing a layout with details like price etc. Also here is a book button. If user is logged in it should book the room (update the database and set 'available' property of certain room to 0). If not, user should log in.
Everything works fine except update operation.
So, this is my PHP script, which should update database
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$id = $_POST['id'];
$available = $_POST['available'];
//importing database connection script
require_once('dbConnect.php');
//Creating sql query
$sql = "UPDATE room SET available = '$available' WHERE id = $id";
//Updating database table
if (mysqli_query($con,$sql)) {
echo 'Room Is Booked Successfully';
}
else {
echo 'Could Not Book Room, Try Again';
}
//closing connection
mysqli_close($con);
}
This is my android volley function:
private void update() {
available = Integer.valueOf(0).toString();
id = Integer.valueOf(Config.SELECTED_ITEM + 1).toString();
StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.BOOK_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(DetailsActivity.this, response, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(DetailsActivity.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put(Config.KEY_ID, id);
params.put(Config.KEY_AVAILABLE, available);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
Everytime I'm getting this message: Could Not Book Room, Try Again. Help me please.