java - 如何使用android在数据库中登录用户信息
问题描述
private void LogInFunction() { Map<String,String> 参数 =new HashMap<String,String>();
RequestQueue rq = Volley.newRequestQueue(this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, "http://10.0.2.2/CPanelNewsApp/Usercheck.php?email="+edemail.getText().toString()+"&&"+"password="+edpass.getText().toString(),
null,new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("dishs");
// Toast.makeText(getApplicationContext(),"数据已发送到服务器:) ",Toast.LENGTH_SHORT).show();
String stat = jsonArray.getJSONObject(0).get("Stat").toString();
// Toast.makeText(getApplicationContext(),"欢迎用户 :) stat = "+stat,Toast.LENGTH_SHORT).show();
if(stat.matches("1")){
//receive user data from database;;;
userId = (jsonArray.getJSONObject(0).get("id").toString());
userName = (jsonArray.getJSONObject(0).get("name").toString());
userPhone = (jsonArray.getJSONObject(0).get("email").toString());
userEmail = (jsonArray.getJSONObject(0).get("phone").toString());
userPassword = (jsonArray.getJSONObject(0).get("password").toString());
// Toast.makeText(getApplicationContext(),"我们找到数据",Toast.LENGTH_SHORT).show();
//send user data to EditData.java;;;
Intent intent = new Intent(MainActivity.this,ViewCats.class);
intent.putExtra("userId",userId);
intent.putExtra("userName",userName);
intent.putExtra("userPhone",userPhone);
intent.putExtra("userEmail",userEmail);
intent.putExtra("userPassword",userPassword);
startActivity(intent);
}else{
Toast.makeText(getApplicationContext(),"No User !!! ",Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
// by prog hazem ahmad <<< www.beprogrammer.org >>> ...
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO: Handle error
Toast.makeText(getApplicationContext(),"Error Response 102",Toast.LENGTH_SHORT).show();
}
}
解决方案
推荐阅读
- java - 需要有关如何将数字添加到 jlabel 的帮助
- excel - 如何在 Excel 2013 中比较 2 张工作表后创建查询以返回结果
- react-native - 如何从多 TextInput 中取回文本?
- c++ - C++ 编译器会内联包含少量术语的 for 循环吗?
- javascript - 如何添加链接到下拉/自动完成提交?
- docker - 在公司范围内管理 docker 节点和集群的最佳实践
- angular - 为什么我在 ngModel 中只看到私有类属性
- java - 为什么复制文件时android应用程序冻结?
- java - 是否可以从此处的标题中删除“throw IllegalArgumentException”?
- android - 平滑滚动到位置,无需每次都下载所有项目