0

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);
7
  • what kind of database? Commented Aug 17, 2015 at 19:29
  • @lispHK01 MySql utf8_unicode Commented Aug 17, 2015 at 19:34
  • In database you won't see the accents because get encoded, you will see them again when you retrieve the data. Also, in your update query if [id] is a int column, you should put $e_id instead of '$e_id' Commented Aug 17, 2015 at 19:41
  • @AlbertoFernández This is not the problem. I have 2 more classes inserting the data very well with "normal strings": "Vou" and "Talvez". Problem is accents and blank space between the 2 words Commented Aug 17, 2015 at 19:55
  • Please, confirm that your PHP variables are correct. This states that you cannot have extended characters, nor spaces in variable names. it should be either "Nao_Vou" or something. check the link for naming conventions. Commented Aug 17, 2015 at 20:06

1 Answer 1

1

From the documentation, PHP variables should not contain special characters, or spaces, or anything out of

a letter is a-z, A-Z, and the bytes from 127 through 255 (0x7f-0xff). 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.