简体   繁体   中英

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 :

<?php
$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" );

mysqli_stmt_execute($statement);

$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>() {
        @Override
        public void onResponse(String response) {
            try {
                JSONObject jsonResponse = new JSONObject(response);
                boolean success = jsonResponse.getBoolean("success");

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

    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);
    queue.add(request);

}

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 );

}

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

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);

mysqli_stmt_execute($statement);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM