如何检查用户是否已经存在于注册表中?

时间:2017-10-17 06:26:50

标签: java android json userlocation

我已经在android中创建了一个项目用户登录,如果用户已经存在,我如何使用像PHP(lol)这样的简单代码进行检查然后进行祝酒。你有任何sugestions?

这是我的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

1 个答案:

答案 0 :(得分:0)

电子邮件字段在数据库中应该是唯一的。在插入数据之前,您需要检查电子邮件是否已存在。

我相信这会回答您的问题:enter image description here