Я разрабатываю приложение для Android, и у меня возникают проблемы с регистрацией моего пользователя с помощью PHP и oracle 10g. Я не могу найти примеров, работающих с оракулом.
Это мой php-код:
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");
Это мой код Java:
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();
}
}
}
Я работаю с классом JSONParser. Что-то не так с моим кодом? Я не могу понять, что случилось. Есть ли рабочий пример, который я могу использовать?
Изменение: в моем Android-лог файле есть следующее:
Пропустили 140 кадров! Приложение может делать слишком много работы над своей основной нитью. Окно уже сфокусировано, игнорируя усиление фокусировки: com.android.internal.view.IInputMethodClient$Stub$Proxy@1ee6a42c attribute = null, token = android.os.BinderProxy@3ed2ccef не удалось выполнить вход в двоичный журнал событий: переполнение. Чрезмерная настройка задержки: 195 мс Пользователь [0] Сбрасывание статистики использования на диск
В вашем методе makeHttprequest() вы запрашиваете запрос на получение, но в вашем php-скрипте вы проверяете его в почтовом запросе.