마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 php mysql 로그인

0 추천
안녕하세요 조금씩 만들면서 공부중인 사람입니다.

안드로이드 php mysql 로 로그인을 구현중인데요;

 

id 중복확인에서 자꾸 " 중복된 id "라고만 나오네요 모든 입력 값들이요..

전체적으로 한번 봐주시길 바랍니다. 전체 소스는 아니구요. id 중복확인 쪽 코드만 넣었습니다.

 

 

------------------------------------php-------------------------------------

<?php

 session_start();

 include('phpConnect.php');
 
 $id = $_POST['ID'];
 
 $r = mysql_query("select ID from User_Info where ID='$id'", $con);
 
 $row = mysql_fetch_row($r);
 
 $create = "0";
 
 $failed = "1";
 
 if($r == "0")
 {
  print(json_encode($create));
 }
 else
 {
  print(json_encode($failed));
 }
?>

 

-----------------------------------------android A activiy ----------------------------

 

public class controlMysql extends Thread {

    public static boolean active = false;
    Handler mHandler = new Handler();
    String url = null;
    int gettype = 0;

    public controlMysql(String id)
    {
        String chk_url = "";

        mHandler = new Handler();
        String userId = id;

        url = chk_url + userId;
        gettype = 1;
    }

    public controlMysql(String id, String name, String age, String phone, String mail, String address, String pw)
    {

        String insert_url = "";
        String userId = id;
        String userName = name;
        String userAge = age;
        String userPhone = phone;
        String userMail = mail;
        String userAddress = address;
        String userPw = pw;

        url = insert_url+userId+userName+userAge+userPhone+userMail+userAddress+userPw;
        gettype = 2;
    }

    @Override
    public void run()
    {
        super.run();

        if(active)
        {
            StringBuilder jsonHtml = new StringBuilder();

            try
            {
                URL phpUrl = new URL(url);
                HttpURLConnection con = (HttpURLConnection)phpUrl.openConnection();

                if(con != null)
                {
                    con.setConnectTimeout(10000);
                    con.setUseCaches(false);

                    if(con.getResponseCode() == HttpURLConnection.HTTP_OK)
                    {
                        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
                        while(true)
                        {
                            String line = br.readLine();

                            if(line == null)
                                break;

                            jsonHtml.append(line+"\n");

                            br.close();
                        }
                        con.disconnect();
                    }
                }
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

            show(jsonHtml.toString());
        }
    }

    void show(final String result)
    {
        mHandler.post(new Runnable()
        {
            @Override
            public void run()
            {
                switch(gettype)
                {
                    case 1:
                        ChkId.chkidResult(result);
                        break;

                    case 2:
                        Login.regist_result(result);
                        break;

                }
            }
        });
    }

}

------------------------------------ android B activity --------------------------------

    static public void chkidResult(String result)
    {

        if(result.equals("0"))
        {
            description.setText("사용이 가능합니다.");
            chkok=true;
        }
        else
        {
            description.setText("중복된 ID 입니다.");
            chkok = false;
        }
    }

 

여기서 description.setText("중복된 ID 입니다."); 만 실행이 되버리네요;;

 

잘못된 점 바로잡아주시길 바랍니다.
알파고 (4,320 포인트) 님이 2017년 2월 16일 질문
알파고님이 2017년 2월 22일 reshown
chkidResult(String result) 의 result에는 무슨 값이 넘어오나요?
php 에서 0이 넘어옵니다! 제 생각대로라면요 ㅠㅠ
생각이 아니라 실제로 뭐가 넘어오냐고요

1개의 답변

+1 추천
 
채택된 답변
mysql의 id 필드는 기본키로 자동 추가되는 걸로 기억하는데, 아마 안드로이드 코드에서는 id가 유저의 로그인 아이디로 쓰고 있지는 않은지 의심되네요.
쎄미 (162,410 포인트) 님이 2017년 2월 17일 답변
알파고님이 2017년 3월 5일 채택됨
id 보낼때도 , run이 실행될 때도 Log.e가 출력됩니다;;; Log.e가 출력된다는 건 뭔가 문제가 있다는 뜻이죠??
제가 지금까지의 상황을 정리해 본 결과;

1.php에서 웹상으로 db연동 확인.

2.안드로이드에서 php로 연결하는 ip로 php파일을 웹상에서 실행시켰을 때, 1번과 동일한 값 출력 확인.

3. Log.e 로 확인해 봤을때, id보낼때 받을때 모두 Log.e가 출력됩니다//

4.php에서 보내는 값(0)이 안드로이드로 들어오긴 하는데 에러로그가 (Log.e) 출력됩니다;



php에서 int 0 변수를 보내고


안드로이드에서

if(result.charAt(0) == 0)

이렇게 하니 원하던 결과가 나오긴 했습니다만 ,

에러 로그가 왜 출력되는지 모르겠습니다;;
제가 묻는 건 출력되는 값이 무엇이냐입니다. 보낸 값이 출력된다는게 아니라 실제 출력되는 로그를 적으시라고요.
해결했습니다. 답변 감사드립니다.
...