douxiongzhen2126 2015-03-11 18:43
浏览 32

基本的MySql Android登录不起作用

LoginPhp.java

    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog = ProgressDialog.show(LoginPhp.this, "",
                    "Validating user...", true);

            String username = String.valueOf(et.getText());
            String password = String.valueOf(pass.getText());

            login(username, password);


        }
    });
}

void login(String username, String password){
    Config config = Config.getInstance();
    Log.i("--******------","vghjbkj");
    try {
        JSON_Parser p = new JSON_Parser();
        String url ="http://" + config.getIp() + "/parkinson/check.php?username=" + username + "&password=" + password;
        Log.i("---------",url);


        JSONObject results = p.readJsonFromUrl(url);
        System.out.println(results.toString());
        Log.i("--/////////////------",url);
        if(!results.has("error"))
        {
            String result = results.getString("success");
            Log.i("--------",result);
            if(result.equalsIgnoreCase("true"))
            {
                Intent intent = new Intent(getApplicationContext(),Menu.class);
                startActivity(intent);
                finish();
            }else{
                showAlert();
            }
        }else{
           showAlert();
        }


    }catch(Exception e )
    {
Log.i("erdtrfyguyhbijnk","-------------------------------------ihuiu");
    }
}

}

When I go to login it gets stuck on 'Validating user...' I think it has something to do with the Json_Phase class where it says .openSteam()? As wwhen i debug it it wont go past that line..

But I'm not sure how to fix the problem

public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {

    InputStream is = null;
    try {

        is = new URL(url).openStream();

        BufferedReader rd = new BufferedReader(
                new InputStreamReader(is, Charset.forName("UTF-8"))
        );
        String jsonText = readAll(rd);
        Log.i("", jsonText);
        JSONObject json = new JSONObject(jsonText);

        return (json);

    } finally {
        if (is != null) {
            is.close();
        }
    }

PHP file

  <?php
    include('connect.php');

    $username = $_GET['username'];
    $password = $_GET['password'];
    $query_search = "select * from tbl_user where username = '".$username."' AND        password = '".$password. "'";
    $query_exec = mysql_query($query_search) or die(mysql_error());
    $rows = mysql_num_rows($query_exec);
    //echo $rows;
    if($rows == 0) { 
    echo '{"success":"false"}'; 
        }
     else  {
        echo '{"success":"true"}'; 
    }
    ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置