无法使用Volley更新MySQL数据库

时间:2016-08-15 21:30:28

标签: php android mysql android-volley

我希望这是一个小错误..但我看不到它。不是伟大的PHP,但这里去。

我成功获取数据,并且我成功上传数据。但是当它更新时......它没有发生。

PHP

<?php
Error_reporting(0);
header('Content-Type: application/json');

//https://www.simplifiedcoding.net/retrieve-data-from-mysql-database-in-android-using-volley/
$response = array("error" => FALSE);
require_once 'include/DB_Connect.php';
$db = new Db_Connect();
$conn= $db->connect();


if(isset($_POST['id'], $_POST['bio'], $_POST['photo'], $_POST['name'])){

  //CREATE FIELDS
    $id = $_POST['id'];
    $name = $_POST['name'];
    $bio = $_POST['bio'];
    $photo = $_POST['photo'];

      echo json_encode($response);

    //ADD PARAMETERS TO METHOD 
    //$family_member = $db->updateFamilyMember($id,$name);
    //$family_member = $db->updateFamilyMember($id,$name,$bio);

    $result = mysqli_query("UPDATE family_member SET name = '$name' WHERE id = $id")or die(mysqli_error());

    $row_count = mysqli_affected_rows();

    if($row_count>0){
         $response["success"] = 1;
         $response["message"] = "Updated Sucessfully.";
     }
    else{
        $response["success"] = 0;
        $response["message"] = "Failed To Update."; 
     } 
  // echoing JSON response
  echo json_encode($response);
}
?>

SQL设置

enter image description here

Android - updateMethod

private void updateFamilyMember() {
        final ProgressDialog loading = ProgressDialog.show(getActivity(), "Loading Data", "Please wait...", false, false);

        //Showing the progress dialog
        StringRequest strReq = new StringRequest(Request.Method.POST,
                PHPConfigURLS.URL_UPDATE_FAMILY_MEMBER, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {

                Log.d(TAG, "Login Response: " + response);

                loading.dismiss();
                try {
                    JSONObject jObj = new JSONObject(response);
                    boolean error = jObj.getBoolean("error");
                    if (!error) {

                        Toast.makeText(getActivity(), "Update successfully registered", Toast.LENGTH_LONG).show();

                    } else {

                        String errorMsg = jObj.getString("error_msg");
                        Toast.makeText(getActivity(),
                                errorMsg, Toast.LENGTH_LONG).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener()

                {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        loading.dismiss();

                        Toast.makeText(getActivity(), volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
                        Log.i(TAG, volleyError.getMessage().toString());
                    }
                }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                //Converting Bitmap to String
                int id = familyMemberID;
                //Creating parameters
                Map<String, String> params = new Hashtable<>();
                //Adding parameters
                params.put("id", String.valueOf(id));
                params.put("name", mNameField.getText().toString());
                params.put("bio", mBio.getText().toString());
                params.put("photo", mPhotoPath.toString());
                //returning parameters
                return params;
            }
        };

        //Creating a Request Queue
        RequestQueue requestQueue = Volley.newRequestQueue(getActivity());

        //Adding request to the queue
        requestQueue.add(strReq);
    }

我知道这是愚蠢的事,但很难找到愚蠢的错误......有人能指出这个愚蠢的错误吗...很感激

米/ IwIew.png

0 个答案:

没有答案