我已经让一个项目用户在 android 中登录,我如何使用 PHP (lol) 等简单代码检查用户是否已经存在,然后敬酒。你有什么建议吗?
这是我的爪哇
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
电子邮件字段在数据库中应该是唯一的。在插入数据之前,您需要检查电子邮件是否已存在。
我相信这回答了您的问题:如何使用PHP检查MySQL中是否已存在用户