Android 애플리케이션에서 EditText
의 심볼을 가져 와서 데이터베이스에 저장하려고합니다. 데이터베이스에서 가져와 편집하고 있습니다. 예를 들어,이 기호는 μ
입니다. 그것은 잘 retrived됩니다,하지만 편집하고 변경 사항을 저장하면 심볼은 ?
로 저장되며, 나는 왜 그런지 모르겠다.edittext에서 심볼을 가져 와서 데이터베이스에 저장하십시오.
내 PHP 파일이 추가되었습니다 :
mysql_query("SET NAMES 'utf8'");
header("Content-type: application/json; charset=utf-8");
이것은 자바 코드
class SaveglossaryDetails extends AsyncTask<String, String, String> {
/**
* Saving glossary
* */
protected String doInBackground(String... args) {
// getting updated data from EditTexts
String Name = name.getText().toString();
String Description = description.getText().toString();
String Symbol = symbol.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(TAG_GID, gid));
params.add(new BasicNameValuePair(TAG_NAME, Name));
params.add(new BasicNameValuePair(TAG_DESCRIPTION, Description));
params.add(new BasicNameValuePair(TAG_SYMBOL, Symbol));
// sending modified data through http request
// Notice that update glossary url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_update_glossary,"POST", params);
// check json success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully updated
Intent i = new Intent(getApplicationContext(), AdminGlossary.class);
i.putExtra("admin", admin);
startActivity(i);
} else {
// failed to update glossary
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
내 PHP 코드
<?php
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['ID_glossary']) && isset($_POST['symbol']) && isset($_POST['name']) && isset($_POST['description'])) {
$ID_glossary = $_POST['ID_glossary'];
$name = $_POST['name'];
$symbol = $_POST['symbol'];
$description = $_POST['description'];
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
mysql_query("SET NAMES 'utf8'");
// mysql update row with matched pid
$result = mysql_query("UPDATE glossary SET Symbol='$symbol', Name = '$name', Description = '$description' WHERE ID_Glossary = $ID_glossary");
header("Content-type: application/json; charset=utf-8");
// check if row inserted or not
if ($result) {
// successfully updated
$response["success"] = 1;
$response["message"] = "glossary successfully updated.";
// echoing JSON response
echo json_encode($response);
} else {
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
db_connect입니다
<?php
/**
* A class file to connect to database
*/
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
mysqli_query($link, "SET SESSION CHARACTER_SET_RESULTS =utf8;");
mysqli_query($link, "SET SESSION CHARACTER_SET_CLIENT =utf8;");
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
?>
어떻게 해결할 수 있습니까? 문제는 어디에 있습니까?
문자열 로깅을 시도하여 Java가 값을 올바르게 캡처하지 못하는지 확인할 수 있습니까? –
@ Jays. 문제는 그것 때문에 가상 장치에서 응용 프로그램을 실행할 수 없다는 것입니다. 왜냐하면 그 큰 장치는 실제 장치에서만 실행할 수 있기 때문입니다. – lama
아, 안드로이드 SDK가 있고 장치에서 USB 디버깅을 활성화하면 컴퓨터에서 DDMS를 사용하여 콘솔을 볼 수 있습니다. @ 라마 –