I´m having a problem with this string: "Não Vou". It means "I don´t go". I´m trying to insert it into database with php/json file.
When I remove blank space and ~ accent it works fine.
What I have tried:
- changed iso-8859-1 to utf-8;
- changed eclipse encoding to utf-8;
- changed print(json_encode($flag)) to print(json_encode('utf8_encode', $flag));
Have read similar posts but any of them helped me.
public class insertNo extends AsyncTask<String, Boolean, Boolean>{ @Override protected Boolean doInBackground(String... params) { ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("e_id", subString)); nameValuePairs.add(new BasicNameValuePair("Não Vou", no)); try{ HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://mywebsite.com/includes/insert_counter.php"); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity entity = httpResponse.getEntity(); inputStream = entity.getContent(); Log.e("pass 1", "connection success"); }catch(Exception e){ Log.e("Fail 1", e.toString()); Log.e("Invalid IP", e.toString()); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder stringBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { stringBuilder.append(line + "\n"); } inputStream.close(); result = stringBuilder.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) { Log.d("Insert success", result); } else { Log.d("Sorry son", result); } } catch (Exception e) { Log.e("Fail 3", e.toString()); } return null; }}
php file
include_once("db_connect.php");
$e_id = $_REQUEST["e_id"];
$yes = $_REQUEST["Vou"];
$no = $_REQUEST["Não Vou"];
$maybe = $_REQUEST["Talvez"];
$flag['code']=0;
if(isset($yes)){
$r = mysqli_query($mysqli, "UPDATE table1 SET yes = yes + 1 WHERE id='$e_id'");
$flag['code']=1;
}else if(isset($no)){
$r = mysqli_query($mysqli, "UPDATE table1 SET no = no + 1 WHERE id='$e_id'");
$flag['code']=1;
}else if(isset($maybe)){
$r = mysqli_query($mysqli, "UPDATE table1 SET maybe = maybe + 1 WHERE id='$e_id'");
$flag['code']=1;
}
print(json_encode($flag));
mysqli_close($mysqli);