-2
我已經做了一個項目用戶在Android登錄,我如何檢查一個簡單的代碼就像一個PHP(哈哈)如果用戶已經存在,然後做一個敬酒。你有什麼要求嗎?如何做一個簡單的方法來檢查用戶是否已經存在於註冊表中?
這裏是我的Java
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("nama", namauser.getText().toString()));
params.add(new BasicNameValuePair("fakunit", spPropellant.getSelectedItem().toString()));
params.add(new BasicNameValuePair("notelp", notelpon.getText().toString()));
params.add(new BasicNameValuePair("email", email.getText().toString()));
//params.add(new BasicNameValuePair("npwp", username.getText().toString()));
params.add(new BasicNameValuePair("password", password.getText().toString()));
JSONObject json = jsonParser.makeHttpRequest(url_insert,
"POST", params);
// check log cat fro response
Log.d("Create Response", json.toString());
// check for success tag
try {
int success = json.getInt(TAG_SUCCESS); //ambil success value yang dikirim php
if (success == 1) { // cek jika variable success = 1, berarti registrasi berhasil
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Register Success. Please Log in!", Toast.LENGTH_LONG).show();
}});
Intent i = new Intent(Register.this, Login.class);
startActivity(i);
finish();
}
else {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Register GAGAL.", Toast.LENGTH_LONG).show();
}});
Intent i = new Intent(Register.this, Register.class);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
dialog.dismiss();
}
這PHP代碼寄存器 phpregister
只是讓電子郵件獨特..感謝您的幫助 –
插入數據時就可以收到不止一個類型的錯誤,並不一定是該電子郵件是獨一無二的。我仍然相信事先檢查電子郵件會更好。如果您之後收到錯誤,您知道這不是因爲電子郵件。 –