當我嘗試登錄時,我一直收到「無效的電子郵件或密碼」消息。我的錯在哪裏?你有解決這個問題的建議嗎?或者有沒有獲得有關此信息的來源?當點擊按鈕時,出現「無效」信息
這是mainactivity.java
,這部分是關於登錄按鈕。當我點擊按鈕時,它不檢查數據庫獲取信息,也不會切換到另一個頁面;
private View.OnClickListener btnGirisListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
email = etmail.getText().toString();
password = etpassword.getText().toString();
login(email, password);
}
};
private void login(final String email, String password){
class LoginAsync extends AsyncTask<String,Void,String>{
private Dialog loadingDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
loadingDialog=ProgressDialog.show(MainActivity.this,"Please wait", "Loading..");
}
@Override
protected String doInBackground(String... params) {
String mail = params[0];
String pass = params[1];
InputStream is = null;
List<NameValuePair>nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("E-mail",mail));
nameValuePairs.add(new BasicNameValuePair("Password", pass));
String result = null;
try{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://******");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(String result) {
String s = result.trim();
loadingDialog.dismiss();
if(s.equalsIgnoreCase("success")){
Intent intent = new Intent(MainActivity.this, Giris.class);
intent.putExtra(E_MAIL, email);
finish();
startActivity(intent);
}else{
Toast.makeText(getApplicationContext(),"Invalid E-mail or Password.",Toast.LENGTH_SHORT).show();
}
}
}
LoginAsync la = new LoginAsync();
la.execute(email,password);
}
};
我試圖更改php文件,但無法獲得任何解決方案。 和uyegiris.php
文件;
<?php
define('DB_USER', "*******"); //Blanks are full.
define('DB_PASSWORD', "*****");
define('DB_DATABASE', "*****");
define('DB_SERVER', "*****");
$con = mysqli_connect(DB_USER,DB_PASSWORD,DB_DATABASE,DB_PASSWORD);
$Email = $_POST['Email'];
$Sifre = $_POST['Sifre'];
$sql = "select * from uyeler where Email='$Email' and Sifre='$Sifre'";
$res = mysqli_query($con,$sql);
$check = mysqli_fetch_array($res);
if(isset($check)){
echo 'success';
}else{
echo 'failure';
}
mysqli_close($con);
?>
我認爲在PARAMS一些錯字錯誤,如設置在PHP端的移動結束「電子郵件」和「電子郵件」在移動端也使用'Sifre'而不是'Password'。 –
相同的密碼在PHP它是'Sifre'和在Android它''密碼' –
爲什麼你定義整個AsyncTask類在你的登錄方法。在登錄方法和登錄方法外定義AsyncTask只需調用 LoginAsync la = new LoginAsync(); la.execute(email,password); – Danger