I made an application that sends few text inputs from android to my online database. My application ran good, but some users reported that they can't use Arabic text. So I tried, and When I send Arabic text in the database it appears as ????? ????? ??????
My php script:
<?php
$connect = mysql_connect($db_host,$db_uid,$db_pass) or die('could not connect');
mysql_select_db($db_name);
if(mysql_errno($connect))
{
die("Failed to connect to MySQL: " . mysql_error());
}
else
{
echo "success";
mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8');
}
$name = isset($_POST['name']) ? $_POST['name'] : '';
$sex = isset($_POST['sex']) ? $_POST['sex'] : '';
$nationality = isset($_POST['nationality']) ? $_POST['nationality'] : '';
$query = mysql_query( "insert into people (name, sex, nationality) values (N'$name' ,N'$sex', N'$nationality') ", $connect);
print_r($_POST);
if(!$query) echo mysql_error();
mysql_close($connect);
?>
my Android code:
DefaultHttpClient httpclient= new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.xxxxxxxx.com/thescript.php");
Log.e("done 1st","its here");
try
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", Name.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("sex", Sex.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("nationality", Nationality.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.e("done", String.valueOf(response));
}
I tried few stuff as you can see but none worked.
and when using insert into using online pc .php I get like this : لببي
---------
My Database settings are:
The table collation is utf8_general_ci
and its type is MyISAM
and the collumns (name,sex,nationality) inside it:
type is varchar
and collation is utf8_general_ci
ex.
the output should be علي
but it's ???