我对这个字符串有疑问:“NãoVou”。这意味着“我不去”。我试图用php / json文件将其插入数据库。
当我删除空格和〜重音时,它可以正常工作。
我尝试过:
已经阅读了类似的帖子,但其中任何一个都帮助了我。
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文件
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);
答案 0 :(得分:1)
From the documentation,PHP变量不应包含特殊字符,空格或
之外的任何内容a letter is a-z, A-Z, and the bytes from 127 through 255 (0x7f-0xff).