我正在使用 php 从 MYSQL 获取用户名和密码...代码没问题,但是当我显示警告栏时,我显示警告栏,你想注销吗?然后我的 LoginActivity 出现在图片中。即使用户输入了错误的用户名或密码,也会获取以前的登录数据。这是我的php代码
<?php
include("db.php");
include("database.php");
$uname=$_REQUEST['Username'];
$upassword=$_REQUEST['Password'];
if($upassword!='' && $uname!=''){
$resultFac = SelectSingleRow("FacultyLogin","Password='$upassword' AND Username='$uname'","");
if($resultFac['FacultyID']!=''){
$facid= $resultFac['FacultyID'];
$resultEmp = SelectSingleRow("tblFaculty","ID='$facid'","");
if($resultFac['ID']!=''){
$empid= $resultEmp['EmployeeID'];
$response["Emp_id"]=$empid;
$response["flag"]=1;
echo json_encode($response);
}
}
else{
$response["flag"]=0;
echo "Please enter correct user name password";
echo json_encode($response);
}
}else{
$response["flag"]=0;
echo json_encode($response);
echo "Please enter both the fields";
}
?>
和我的登录活动
public class LoginActivity extends Activity {
int flag;
int empid;
String username;
String password;
EditText edUsername,edPassword;
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
JSONArray jarray;
ArrayList<HashMap<String, String>> productsList;
private static String url_faculty_login = "http://10.0.2.2/xyz/login_check.php";
private static final String TAG_EMPLOYEE = "employee_id";
private static final String TAG_PID = "pid";
private static final String TAG_NAME = "name";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
// setTitleColor(1);
Intent i=new Intent();
edUsername=(EditText) findViewById(R.id.edUserName);
edPassword=(EditText) findViewById(R.id.edPassword);
String clear="clear";
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
LoginActivity.this.finish();
// LoginActivity.
}
//@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
LoginActivity.this.finish();
}
//onClick login.xml Button
public void signIn(View view) {
//call to inner class
if(edUsername!=null && edPassword!=null )
{
new LoadAllProducts().execute();
}
else
{
Toast.makeText(getApplicationContext(), "Enter Both Fields", Toast.LENGTH_LONG);
}
}
class LoadAllProducts extends AsyncTask<String, String, String> {
private static final String Emp_id = "Emp_id";
public String doInBackground(String... args) {
username=edUsername.getText().toString();
password=edPassword.getText().toString();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Username", username));
params.add(new BasicNameValuePair("Password", password));
JSONObject json = jParser.makeHttpRequest(url_faculty_login, "POST", params);
Log.d("Username n password: ", json.toString());
try {
flag=json.getInt("flag");
Log.d("flags",""+flag);
} catch (JSONException e) {
e.printStackTrace();
}
if(flag==1)
{
try
{
empid=json.getInt(Emp_id);
}
catch (JSONException e)
{
e.printStackTrace();
}
Intent i=new Intent(getApplicationContext(),ClassActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtra("Emp_id", ""+empid);
Log.d("Empid",""+empid);
startActivity(i);
}
if(flag==0)
{
Intent i=new Intent(getApplicationContext(),InvalidUPLoginActivity.class);
startActivity(i);
}
return null;
}
}
}