當前我正在使用Android Studio完成我的最後一年項目。幾乎沒有功能可以完成我的移動應用程序。更新功能在Android Studio中不起作用
但是,我的應用程序沒有執行更新功能。
在我的移動應用程序中繼續更新帳戶之前,我使用JSON來提取數據庫中的值。然後將值存儲在更新表單的EditText中。然後我試圖在表單中進行一些更改。當我點擊提交按鈕時,它將進入下一個活動,即查看帳戶。但是,我做了一些更改的值與更新帳戶之前的值相同。我已經在Intent中檢查了編碼或傳遞值,但沒有錯。爲什麼會發生?誰能幫我這個?
我完全失去了從哪裏開始。我仍然是開發Android應用程序的基礎。
我正在使用PHP和MySQL更新數據庫中的值。
這是我在PHP中的編碼。
<?php
$response = array();
include 'db_connect.php';
$db = new DB_CONNECT(); if (isset($_POST['idDoc'])) {
$idDoc = $_POST['idDoc']; $namedoc = $_POST['namedoc'];
$ic = $_POST['ic']; $address = $_POST['address']; $notel = $_POST['notel']; $passwrd = $_POST['passwrd'];
$result = mysql_query("UPDATE `DOCTOR` SET namedoc = '$namedoc', ic = '$ic', address = '$address', noTel = '$notel', passwrd = '$passwrd' WHERE idDoc = $idDoc"); // check if row inserted or not
if ($result) {
// successfully updated
$response["success"] = 1;
$response["message"] = "Account successfully updated.";
echo json_encode($response);
} else {
} } else {
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
echo json_encode($response);
} ?>
以下是更新EditText中的值的代碼。
class updAcc extends AsyncTask<String, String, JSONObject> {
/**
* Before starting background thread Show Progress Dialog
*/
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(updateAccDoc.this);
pDialog.setMessage("Updating accound..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected JSONObject doInBackground(String... params) {
String namedoc = nameDoc.getText().toString();
String iddoc = idDoc.getText().toString();
String icdoc = icDoc.getText().toString();
String address = addDoc.getText().toString();
String notel = notelDoc.getText().toString();
String pass = password.getText().toString();
List<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("idDoc", iddoc));
param.add(new BasicNameValuePair("namedoc", namedoc));
param.add(new BasicNameValuePair("ic", icdoc));
param.add(new BasicNameValuePair("address", address));
param.add(new BasicNameValuePair("notel", notel));
param.add(new BasicNameValuePair("passwrd", pass));
JSONObject json = jsonParser.makeHttpRequest(urll2,
"POST", param);
try {
int success = json.getInt("success");
if (success == 1) {
// successfully updated
Intent intent = new Intent(updateAccDoc.this, docProfile.class);
String ID6 = getIntent().getExtras().getString("idDoc");
intent.putExtra("idDoc", ID6);
startActivity(intent);
finish();
} else {
// failed to update product
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* *
*/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product uupdated
pDialog.dismiss();
}
}
的痕跡說:「不能把字符串轉換成JSON」
對不起。但我真的不明白你想說什麼...... – ChrisHarry