更新数据库表的问题

时间:2016-09-24 10:04:30

标签: php android mysql database

我正在构建一个使用MySQL数据库的应用程序..我正在尝试发送gps坐标以及字符串和整数..坐标发送工作正常..问题是字符串和整数< / p>

这是我的php脚本:

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

这是我的表结构:

database table

并且我认为问题不在于aplication,因为我用于发送双精度(lat,long)和字符串(拾取,目标)的代码之间没有差异..无论如何这是一些我的应用程序代码:

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

}

这是扩展字符串请求的类

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

1 个答案:

答案 0 :(得分:0)

尝试将您的查询更改为类似的内容 - 注意:我猜测您的变量类型为“i”和“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);