如何从android中的php文件中获取rowcount

时间:2015-03-21 09:55:23

标签: php android

我正在将用户输入的用户名和密码与数据库数据进行比较,我使用count来检查它是否等于1或0.

如果它等于1,则editText应设置为1,如果为0,则应设置为0.

我的问题是,即使用户名和密码正确,也始终设置为0.

这是名称值对和与数据库的连接:

    username = etlogUsername.getText().toString();
    password = etlogPassword.getText().toString();
    String output = "";

//setting the NameValuePair
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);

            //adding the string variables inside the nameValuePairs
            nameValuePairs.add(new BasicNameValuePair("user_username", username));
            nameValuePairs.add(new BasicNameValuePair("user_password", password));
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://thesis-account.byethost7.com/workout_select_username.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            //getting the response
            HttpResponse response = httpclient.execute(httppost);

            //setting up the entity
            HttpEntity entity = response.getEntity();

            is = entity.getContent();

这里是将读取数据的json:

JSONArray jArray= new JSONArray(output);

            for(int i = 0;  i <jArray.length() ; i++){
                JSONObject json = jArray.getJSONObject(i);
                COUNT_user_id = json.getInt("num_rows");

                if(COUNT_user_id == 1)
                {
                 isEqual = true;
                }
            }
            etlogUsername.setText(COUNT_user_id+"");

这是php文件:

$sql = mysql_query("SELECT COUNT(user_id) AS num_rows FROM tbl_users
WHERE user_username='{ $username}' && user_password = '{$password}' ");
while($row=mysql_fetch_assoc($sql))
{
$output[]=$row;
}
print(json_encode($output));
mysql_close($con);

0 个答案:

没有答案