用android volley和php将persian值发布到mysql

时间:2017-01-26 18:40:46

标签: php android mysql android-volley

我尝试使用android volley库将波斯值发布到mysql,但它会在我的数据库中发布此值,如下所示:(ااداتت)

我的数据库排序规则是utf8_persian_ci

我的PHP代码:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.util.HashMap;
import java.util.Map;

public class DeviceAddActivity extends AppCompatActivity implements      View.OnClickListener {
    private static final String REGISTER_URL = "http://192.168.43.190/entezam/addphone.php";
    public static final String KEY_CUSTNAME = "Customer_non";
    public static final String KEY_PHONENAME = "Phone_Name";
    public static final String KEY_IMEI = "IMEI";
    public static final String KEY_Mobile ="Mobile";
    public static final String KEY_Status ="Status";
    public static final String KEY_Fault = "Fault";
    public static final String KEY_custfault ="custfault";
    public static final String KEY_max_Cost = "max_Cost";
    public static final String KEY_accesories ="accesories";
    private EditText editTextName;
    private EditText editTextPhoneName;
    private EditText editTextIMEI;
    private EditText editTextMobile;
    private RadioButton ron;
    private RadioButton roff;
    private EditText editTextFault;
    private EditText editTextCustfault;
    private EditText editTextmaxCost;
    private EditText editTextaccesories;
    private Button buttonRegister;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_add);
        editTextName = (EditText) findViewById(R.id.editTextcustname);
        editTextPhoneName = (EditText) findViewById(R.id.editTextphonename);
        editTextIMEI= (EditText) findViewById(R.id.editTextimei);
        editTextMobile = (EditText) findViewById(R.id.etcontactno);
        ron = (RadioButton) findViewById(R.id.rbon);
        roff = (RadioButton) findViewById(R.id.rboff);
        editTextFault = (EditText) findViewById(R.id.etiradzaheri);
        editTextCustfault = (EditText) findViewById(R.id.etiradmoshtari);
        editTextmaxCost = (EditText) findViewById(R.id.etmaxcost);
        editTextaccesories = (EditText) findViewById(R.id.etaccesories);
        buttonRegister = (Button) findViewById(R.id.buttonRegister);
        buttonRegister.setOnClickListener(this);
    }

    private void registerUser(){
        final String Customer_non = editTextName.getText().toString().trim();
        final String Phone_Name = editTextPhoneName.getText().toString().trim();
        final String IMEI = editTextIMEI.getText().toString().trim();
        final String Mobile = editTextMobile.getText().toString().trim();
        final String status;
        if (ron.isChecked()) {
            status = "1";
        } else
            status ="0";
        final String fault = editTextFault.getText().toString().trim();
        final String Custfault = editTextCustfault.getText().toString().trim();
        final String maxCost = editTextmaxCost.getText().toString().trim();
        final String accesories = editTextaccesories.getText().toString().trim();
        StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Toast.makeText(DeviceAddActivity.this,response,Toast.LENGTH_LONG).show();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(DeviceAddActivity.this,error.toString(),Toast.LENGTH_LONG).show();
                }
            }){

            @Override
            protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<String, String>();
                params.put(KEY_CUSTNAME,Customer_non );
                params.put(KEY_PHONENAME,Phone_Name);
                params.put(KEY_IMEI,IMEI);
                params.put(KEY_Status,status);
                params.put(KEY_Fault,fault);
                params.put(KEY_custfault,Custfault);
                params.put(KEY_max_Cost,maxCost);
                params.put(KEY_accesories,accesories);
                params.put(KEY_Mobile,Mobile);
                return params;
            }
        };
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
    }
    @Override
    public void onClick(View v) {
        if(v == buttonRegister){
            registerUser();
        }
    }
}

是我的Android代码:

<div id="forcb1" class="hidden">
    <div id="genComments" class="editGComms"></div>
</div>
---------------------------------------------------------------
document.getElementById("genComments").addEventListener("click", getNetID);

function getNetID(){
    //$(".editGComms").live('click', function(){
        var netid=$("#idofnet").html().trim();

        $(".editGComms").editable("SaveGenComm.php", {
            indicator  : "Saving...",
            tooltip    : "Click to add...",
            style      : "inherit",
            id         : netid,
            name       : "newvalue"
        });
    //});
}

1 个答案:

答案 0 :(得分:0)

尝试通过以下代码将UTF-8的帖子值编码到您的帖子服务中:

public String getBodyContentType() {

                return "application/json; charset=" + getParamsEncoding();

            }