- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个Android应用程序,用户将在其中将用户名和密码保存到数据库中,并将值保存在数据库中。当用户下次来时,他可以登录而不是注册,因此此时用户输入的用户名和密码将与表中保存的数据进行检查,如果用户名与密码匹配,则用户将被引导到下一个页面,否则将显示错误消息。就我而言,注册过程运行良好并且处于登录过程中。当执行过程不起作用时。我正在添加我的 Activity 和 php 文件,用于将数据库与应用程序和 logcat 连接。请检查这一点,如果有任何错误请帮助我解决。谢谢。
Activity
public class SignInActivity extends Activity
{
/*LoginDataBaseAdapter loginDataBaseAdapter;*/
Button btnsignin;
String name,password, psw;
// Progress Dialog
private ProgressDialog pDialog;
// JSON parser class
JSONParser jsonParser = new JSONParser();
// single product url
private static final String url_get_name = "http://iascpl.com/app/get_name_details.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCT = "product";
private static final String TAG_PASSWORD = "password";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.signin_xm);
/*loginDataBaseAdapter=new LoginDataBaseAdapter(this);
loginDataBaseAdapter=loginDataBaseAdapter.open();*/
btnsignin = (Button) findViewById ( R.id.button401);
btnsignin.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new GetNameDetails().execute();
}
});
}
class GetNameDetails extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(SignInActivity.this);
pDialog.setMessage("Loading the result... Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Getting product details in background thread
* */
protected String doInBackground(String... args)
{
final EditText et1 = (EditText) findViewById (R.id.editText401);
final EditText et2 = (EditText) findViewById (R.id.editText402);
name =et1.getText().toString();
password = et2.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name", name));
// getting product details by making HTTP request
// Note that product details url will use GET request
JSONObject json = jsonParser.makeHttpRequest(
url_get_name, "GET", params);
// check your log for json response
Log.d("Single Product Details", json.toString());
// json success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received product details
JSONArray productObj = json
.getJSONArray(TAG_PRODUCT); // JSON Array
// get first product object from JSON Array
final JSONObject product = productObj.getJSONObject(0);
// product with this pid found
// Edit Text
runOnUiThread(new Runnable() {
@Override
public void run()
{
// TODO Auto-generated method stub
try {
psw = product.getString(TAG_PASSWORD);
if (password == psw);
{
Toast.makeText(SignInActivity.this, "Login Successfull", Toast.LENGTH_LONG).show();
Intent i = new Intent(SignInActivity.this,HomePageActivity.class);
startActivity(i);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}else{
// product with pid not found
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url)
{
// dismiss the dialog once got all details
pDialog.dismiss();
}
}
}
PHP
<?php
/*
* Following code will get single product details
* A product is identified by product id (pid)
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET["name"])) {
$name = $_GET['name'];
// get a product from products table
$result = mysql_query("SELECT *FROM numerol WHERE name = $name");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$product = array();
$product["name"] = $result["name"];
$product["passwordr"] = $result["password"];
// $product["price"] = $result["price"];
//$product["description"] = $result["description"];
$product["created_at"] = $result["created_at"];
$product["updated_at"] = $result["updated_at"];
// success
$response["success"] = 1;
// user node
$response["product"] = array();
array_push($response["product"], $product);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
日志猫
11-09 09:18:01.930: E/Trace(5068): error opening trace file: No such file or directory (2)
11-09 09:18:04.410: D/gralloc_goldfish(5068): Emulator without GPU emulation detected.
11-09 09:18:09.303: D/dalvikvm(5068): GC_CONCURRENT freed 83K, 7% free 2712K/2916K, paused 74ms+98ms, total 704ms
11-09 09:18:11.200: I/Choreographer(5068): Skipped 88 frames! The application may be doing too much work on its main thread.
11-09 09:18:20.180: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:23.910: D/dalvikvm(5068): GC_FOR_ALLOC freed 54K, 6% free 2872K/3048K, paused 61ms, total 82ms
11-09 09:18:23.931: I/dalvikvm-heap(5068): Grow heap (frag case) to 3.526MB for 635812-byte allocation
11-09 09:18:24.101: D/dalvikvm(5068): GC_FOR_ALLOC freed 2K, 5% free 3490K/3672K, paused 165ms, total 165ms
11-09 09:18:24.341: D/dalvikvm(5068): GC_CONCURRENT freed 2K, 5% free 3501K/3672K, paused 32ms+95ms, total 242ms
11-09 09:18:24.841: I/Choreographer(5068): Skipped 72 frames! The application may be doing too much work on its main thread.
11-09 09:18:25.690: I/Choreographer(5068): Skipped 83 frames! The application may be doing too much work on its main thread.
11-09 09:18:26.030: I/Choreographer(5068): Skipped 60 frames! The application may be doing too much work on its main thread.
11-09 09:18:26.860: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:28.152: I/Choreographer(5068): Skipped 71 frames! The application may be doing too much work on its main thread.
11-09 09:18:29.102: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:18:30.110: I/Choreographer(5068): Skipped 44 frames! The application may be doing too much work on its main thread.
11-09 09:18:30.522: I/Choreographer(5068): Skipped 34 frames! The application may be doing too much work on its main thread.
11-09 09:18:31.310: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:33.371: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:33.580: I/Choreographer(5068): Skipped 36 frames! The application may be doing too much work on its main thread.
11-09 09:18:37.130: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:18:37.562: I/Choreographer(5068): Skipped 33 frames! The application may be doing too much work on its main thread.
11-09 09:18:39.361: I/Choreographer(5068): Skipped 45 frames! The application may be doing too much work on its main thread.
11-09 09:18:39.500: I/Choreographer(5068): Skipped 37 frames! The application may be doing too much work on its main thread.
11-09 09:18:41.312: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:44.911: I/Choreographer(5068): Skipped 36 frames! The application may be doing too much work on its main thread.
11-09 09:18:45.660: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:18:47.970: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:18:50.081: I/Choreographer(5068): Skipped 39 frames! The application may be doing too much work on its main thread.
11-09 09:18:51.350: I/Choreographer(5068): Skipped 38 frames! The application may be doing too much work on its main thread.
11-09 09:18:51.720: D/Single Product Details(5068): {"message":"No product found","success":0}
11-09 09:19:12.970: I/Choreographer(5068): Skipped 85 frames! The application may be doing too much work on its main thread.
11-09 09:19:13.170: I/Choreographer(5068): Skipped 43 frames! The application may be doing too much work on its main thread.
11-09 09:19:18.532: I/Choreographer(5068): Skipped 42 frames! The application may be doing too much work on its main thread.
11-09 09:19:18.740: I/Choreographer(5068): Skipped 47 frames! The application may be doing too much work on its main thread.
11-09 09:19:24.440: I/Choreographer(5068): Skipped 76 frames! The application may be doing too much work on its main thread.
11-09 09:19:24.630: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:19:25.001: I/Choreographer(5068): Skipped 51 frames! The application may be doing too much work on its main thread.
11-09 09:19:25.610: I/Choreographer(5068): Skipped 146 frames! The application may be doing too much work on its main thread.
11-09 09:19:26.520: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:19:27.412: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:19:28.701: D/Single Product Details(5068): {"message":"No product found","success":0}
11-09 09:19:51.432: I/Choreographer(5068): Skipped 54 frames! The application may be doing too much work on its main thread.
11-09 09:19:53.631: D/dalvikvm(5068): GC_CONCURRENT freed 166K, 8% free 3740K/4028K, paused 74ms+101ms, total 332ms
11-09 09:19:54.360: I/Choreographer(5068): Skipped 112 frames! The application may be doing too much work on its main thread.
11-09 09:19:54.560: I/Choreographer(5068): Skipped 33 frames! The application may be doing too much work on its main thread.
11-09 09:19:55.591: I/Choreographer(5068): Skipped 195 frames! The application may be doing too much work on its main thread.
11-09 09:19:55.921: I/Choreographer(5068): Skipped 80 frames! The application may be doing too much work on its main thread.
11-09 09:19:56.150: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:19:56.562: I/Choreographer(5068): Skipped 46 frames! The application may be doing too much work on its main thread.
11-09 09:19:56.831: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:19:56.955: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:19:57.471: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:19:57.662: I/Choreographer(5068): Skipped 36 frames! The application may be doing too much work on its main thread.
11-09 09:19:58.100: I/Choreographer(5068): Skipped 41 frames! The application may be doing too much work on its main thread.
11-09 09:19:58.350: I/Choreographer(5068): Skipped 36 frames! The application may be doing too much work on its main thread.
11-09 09:19:59.010: I/Choreographer(5068): Skipped 30 frames! The application may be doing too much work on its main thread.
11-09 09:19:59.661: D/Single Product Details(5068): {"message":"No product found","success":0}
11-09 09:20:46.300: I/Choreographer(5068): Skipped 35 frames! The application may be doing too much work on its main thread.
11-09 09:23:11.740: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:25:55.341: I/Choreographer(5068): Skipped 32 frames! The application may be doing too much work on its main thread.
11-09 09:26:51.270: I/Choreographer(5068): Skipped 38 frames! The application may be doing too much work on its main thread.
11-09 09:27:01.220: I/Choreographer(5068): Skipped 58 frames! The application may be doing too much work on its main thread.
11-09 09:28:31.342: I/Choreographer(5068): Skipped 31 frames! The application may be doing too much work on its main thread.
11-09 09:29:01.193: I/Choreographer(5068): Skipped 37 frames! The application may be doing too much work on its main thread.
最佳答案
doInBackground() 不应该处理 Activity 中的 UI,因此在处理 doInBackground 时显示 toast 并不是一个好主意。使用 onPostExecute() 处理 UI已编辑!
class GetNameDetails extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(SignInActivity.this);
pDialog.setMessage("Loading the result... Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Getting product details in background thread
* */
protected String doInBackground(String... args)
{
final EditText et1 = (EditText) findViewById (R.id.editText401);
final EditText et2 = (EditText) findViewById (R.id.editText402);
name =et1.getText().toString();
password = et2.getText().toString();
try { //edited
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("password", password)); //check this please.
// getting product details by making HTTP request
// Note that product details url will use GET request
JSONObject json = jsonParser.makeHttpRequest(
url_get_name, "GET", params);
// check your log for json response
Log.d("Single Product Details", json.toString());
// json success tag
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received product details
JSONArray productObj = json
.getJSONArray(TAG_PRODUCT); // JSON Array
// get first product object from JSON Array
final JSONObject product = productObj.getJSONObject(0);
// product with this pid found
// Edit Text
Intent i = new Intent(SignInActivity.this,HomePageActivity.class);
startActivity(i);
return "true"; // if the login was successful return true string to the onPostExecute(String) and there show the Toast.
}else{
// product with pid not found
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url)
{
// dismiss the dialog once got all details
pDialog.dismiss();
if (file_url == "true")
Toast.makeText(SignInActivity.this, "Login Successfull", Toast.LENGTH_LONG).show();
else
Toast.makeText(SignInActivity.this, "Login unsuccessfull", Toast.LENGTH_LONG).show();
}
}
}
关于php - Android MySql 密码验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19874452/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!