Neo Algeria Neo Algeria - 1 year ago 71
Android Question

an issue with updating database table

i'm building an app which uses MySQL Database .. i'm trying to send a gps coordinates and also strings and an integer .. the coordinates sending is working fine .. the problem is with the strings and the integer

this is my php script :

$con = mysqli_connect("*****", "*****", "******", "*******");

$lat = $_POST["lat"];
$long = $_POST["long"];
$id= $_POST["id"];
$pickup= $_POST["pickup"];
$destination = $_POST["destination"];
$seats= $_POST["seats"];

$statement = mysqli_prepare($con,"Update user SET lat=$lat,long=$long , pickup=$pickup,destination=$destination,seats=$seats WHERE user_id=$id" );


$response = array();
$response["success"] = true;

echo json_encode($response);?>

this is my table structure :

database table

and i don't think that the problem is with the aplication because there is no diffrent between code that i'm using for sending the doubles (lat,long) and strings (pickup , destination).. anyway this is some of my application code :

public void send_gps(String pickup,String destination,int seats,int id, double lat,double long) {

// Response received from the server
Response.Listener<String> responseListener = new Response.Listener<String>() {
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");

} catch (JSONException e) {
AlertDialog.Builder builder2 = new AlertDialog.Builder(MapsActivity.this);
.setNegativeButton("Retry", null)

gps_request request = new gps_request(pickup,destination,Integer.toString(seats),Integer.toString(id),Double.toString(lat),Double.toString(long), responseListener);
RequestQueue queue = Volley.newRequestQueue(this);


and this is the class that extends string request

public class gps_request extends StringRequest {
private static final String LOGIN_REQUEST_URL = "**********************";
private Map<String, String> params;

public gps_request(String pickup,String destination,String seats,String id,String lat, String long, Response.Listener<String> listener) {
super(Method.POST, LOGIN_REQUEST_URL, listener, null);
params = new HashMap<>();

params.put("lat", lat);
params.put("long", long);
params.put("id", id );
params.put("pickup", pickup);
params.put("destination", destination);
params.put("seats", seats );


public Map<String, String> getParams() {
return params;

Answer Source

Try changing your query to something like this - note: I guessed at your variable types "i" and "s".

$statement = mysqli_prepare($con,"UPDATE user SET lat=?, long=?, pickup=?, destination=?, seats=? WHERE user_id=?");

$statement->bind_param("iisssi", $lat, $long, $pickup, $destination, $seats, $id);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download