0

I'm make app in android accept the user name in Arabic Language and store in mysql database on the server but the name when send from app to database , it's stored as ???? .

I'm using the charset in database as UTF-8 and all process on the control panel on web is ok m but from app to database it isn't ok

the asyntask for store information from app to db is :

class InsertInfo extends AsyncTask<String, String, String> {

     @Override
        protected void onPreExecute() {
            super.onPreExecute();

        }

    @Override
    protected String doInBackground(String... arg0) {
        // TODO Auto-generated method stub
        namest=name.getText().toString();
        //emailst=email.getText().toString();
        mobilest=mobile.getText().toString();
        imgst=image_name;


        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("id", evid+""));
        params.add(new BasicNameValuePair("name",namest));
      //  params.add(new BasicNameValuePair("email", emailst));
        params.add(new BasicNameValuePair("mobile", mobilest));
        params.add(new BasicNameValuePair("imgurl", imgst));


     /*   JSONObject json = jsonParser.makeHttpRequest(urlinsert,
                "POST", params);*/


        try
        {
        HttpClient httpclient = new DefaultHttpClient();
        //HttpParams pa = new BasicHttpParams();
        //HttpProtocolParams.setContentCharset(pa, "utf-8");
            HttpPost httppost = new HttpPost(urlinsert);
           // httppost.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,  "application/json"));
            httppost.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse response = httpclient.execute(httppost); 
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
            Log.e("pass 1", "connection success ");

    }
        catch(Exception e)
    {
            Log.e("Fail 1", e.getMessage());
            Toast.makeText(getApplicationContext(), "Invalid IP Address",
            Toast.LENGTH_LONG).show();
    }  

         try
         {
             BufferedReader reader = new BufferedReader
            (new InputStreamReader(is,"UTF-8"),8192);
             StringBuilder sb = new StringBuilder();
             while ((line = reader.readLine()) != null)
        {
                 sb.append(line + "\n");
             }
             is.close();
             result = sb.toString();
        Log.e("pass 2", "connection success ");
    }
         catch(Exception e)
    {
             Log.e("Fail 2", e.toString());
    }  


         try
            {
                    JSONObject json_data = new JSONObject(result);
                    code=(json_data.getInt("code"));

                    if(code==1)
                    {
                Toast.makeText(getBaseContext(), "Inserted Successfully",
                    Toast.LENGTH_SHORT).show();
                    }
                    else
                    {
                 Toast.makeText(getBaseContext(), "Sorry, Try Again",
                    Toast.LENGTH_LONG).show();
                    }
            }
            catch(Exception e)
            {
                    Log.e("Fail 3", e.toString());
            }

        return null;
    }

     protected void onPostExecute(String file_url) {
            // dismiss the dialog once product uupdated

        }

}

I'm trying a lot of methods and at each all i'm using UTF-8 but it's not work as proper manner , can you help me in this case please :(

Alaa Khaled
  • 301
  • 1
  • 3
  • 10
  • 1
    You need to use utf-8 at ALL stages of the process. your android app might send utf-8, your tables might be in utf-8, but if the php->mysql connection ISN'T utf, then you're just going to mangle the text. – Marc B Feb 15 '14 at 01:07
  • take look on this thread http://stackoverflow.com/questions/10409617/send-arabic-from-android-to-php-file – mohammed momn Feb 15 '14 at 01:17
  • I'm used UTF-8 at all stages in app and in php files , the link from you i think he use the same way i'm used it and face the same problem – Alaa Khaled Feb 15 '14 at 01:25

2 Answers2

0

If you did not start utf-8 at the beginning stage then you'll possibly have to go all the way down the line from the server -> connection -> database -> table -> query

  1. MySQL charset: UTF-8 Unicode (utf8)
  2. MySQL connection collation: utf8_general_ci
  3. your database and table collations are set to: utf8_general_ci or utf8_unicode_ci

PHP code:

  1. mysql_query("SET NAMES 'utf8'");
  2. mysql_query('SET CHARACTER SET utf8');

Update:

Did you also uncomment the protocol line in your code?

//HttpParams pa = new BasicHttpParams();    
//HttpProtocolParams.setContentCharset(pa, "utf-8");
Carl McDade
  • 634
  • 9
  • 14
  • I'm already making all of this , and the Arabic is ok in the store and display on the web when enter data from control panel , but the problem in accept Arabic word from application and store it in DB – Alaa Khaled Feb 15 '14 at 09:29
  • and when I'm make manual request through URL and store data it is store in Arabic letter as ok so the problem in the code in android not in the php or mysql DB – Alaa Khaled Feb 15 '14 at 09:31
  • I updated my answer to include checking the client connection code. – Carl McDade Feb 15 '14 at 18:29
  • yes , I tried with/without commented line but no effect on the result ! Do you have another way to send data from app to mysql ? – Alaa Khaled Feb 17 '14 at 03:46
0

Command for creating database to accept all types of language and fonts.

create schema databaseName default charset utf8 collate utf8_bin;
Lokesh Kumar Gaurav
  • 726
  • 1
  • 8
  • 24