Reputation: 2514
I am trying to insert UTF-8 characters(Like username in hindi or tamil language) in MySql with Codeigniter framework. Here is my android side code:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(uploadApi);
try {
List<NameValuePair> nameValuePairs=new ArrayList<>();
nameValuePairs.add(new BasicNameValuePair("key1","विकिपीडिया"));
nameValuePairs.add(new BasicNameValuePair("key2","इण्टरनेट"));
UrlEncodedFormEntity form = new UrlEncodedFormEntity(nameValuePairs);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
and this is server side code in codeigniter:
public function create()
{
$name=$this->input->get_post("name") ;$text=$this->input->get_post("text");
$type=$this->input->get_post("type");$contact=$this->input->get_post("contact");
$mp=$this->input->get_post("mp");$mla=$this->input->get_post("mla");
$position=$this->input->get_post("position");
$config['upload_path'] = './uploads/';
$config['allowed_types'] = '*';
$config['max_size'] = '20000';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('image'))
{
$image="noimage.jpg";
echo $this->upload->display_errors();
}
else
{
$data = $this->upload->data();
$image=$data['file_name'];
}
$data['json']=$this->uploadmodel->insert($name,$image,$text,$contact,$mp,$mla,$type,$position);
echo "Thanks for Sharing";
}
All configuration is set to utf-8 in configuration file. error is i am getting all string like ????????? please tell me where i am doing wrong. Thanks
Upvotes: 0
Views: 468
Reputation: 2514
I added this line:
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
Although i tried with it also before.
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
but the above runs successfully.
Upvotes: 2