当前我正在使用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