Android : android user login using php and oracle database 10g

on Sunday, April 19, 2015


I'm developping an android application and I'm having trouble with my user login using php and oracle databse 10g ! I can't find any examples working with oracle !! This is my php code :



include("connexion.php");

if (!empty($_POST)) {

if (empty($_POST['code_client']) || empty($_POST['password_client'])) {

$response["success"] = 0;
$response["message"] = "One or both of the fields are empty .";


die(json_encode($response)); }

$query = " SELECT * FROM client_mb WHERE code_client = '$code_client'and password_client='$password_client'";

$result = oci_parse($connect, $query);

oci_execute($result);

$row = oci_fetch_array($result);

if (!empty($row)) {

$response["success"] = 1;

$response["message"] = "You have been sucessfully login";

die(json_encode($response)); }

else{

$response["success"] = 0;

$response["message"] = "invalid username or password ";

die(json_encode($response));
}

} else{

$response["success"] = 0;

$response["message"] = " One or both of the fields are empty ";


die(json_encode($response));

}
include("deconnexion.php");


This is my java code :



private static final String TAG_SUCCESS = "success";

private static final String TAG_MESSAGE = "message";

public static final String TAG_CODE = "code_client";

public static final String TAG_PWD = "password_client";


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

txtcode = (EditText) findViewById(R.id.login);
txtpass = (EditText) findViewById(R.id.mdp);

bLogin = (Button) findViewById(R.id.btnLogin);
bLogin.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {


cde = txtcode.getText().toString();
password = txtpass.getText().toString();

if ((TextUtils.isEmpty(cde)) || (TextUtils.isEmpty(password))) {
Toast.makeText(LoginActivity.this,
"Veuillez remplir tous les champs",
Toast.LENGTH_LONG).show();
}

else {

new AttemptLogin().execute(LOGIN_URL);




}

}

});

}

class AttemptLogin extends AsyncTask<String, String, String> {


@Override
protected void onPreExecute() {

super.onPreExecute();
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}

@SuppressWarnings("deprecation")
@Override
protected String doInBackground(String... args) {

// TODO Auto-generated method stub // here Check for success tag
int success;

try {

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(TAG_CODE, cde));
params.add(new BasicNameValuePair(TAG_PWD, password));
Log.d("request!", "starting");

JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "GET",
params);


Log.d("Login attempt", json.toString());
success = json.getInt(TAG_SUCCESS);
if (success == 1) {

Log.d("Successfully Login!", json.toString());
Intent i = new Intent(LoginActivity.this,
MenuEspaceClientActivity.class);

finish();

startActivity(i);
return json.getString(TAG_MESSAGE);
} else {
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}


protected void onPostExecute(String message) {
pDialog.dismiss();

if (message != null) {
Toast.makeText(LoginActivity.this, message, Toast.LENGTH_LONG)
.show();
}


}
}


PS: I'm working with JSONParser class . Is there something wrong with my code ? I can't figure out what's wrong ! Any help pleeeeaaaase ? Is there a working example that I can maybe use ?


0 comments:

Post a Comment