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

php echo 값을 안드로이드로 가져오는것 질문있습니다.

0 추천
안녕하세요 대학교에 다니고 있는 학생입니다.

 

다름이 아니라 제가 프로젝트로 어플을 하나 만들고 있는데요.

 

회원가입 아이디 중복체크 기능입니다 ㅠㅠ

 

음..  아이디를 입력후 중복체크 버튼을 누르면 php에서 아이디 값을 받아 쿼리문을 실행해 중복된 아이디가 있으면 echo 1 없으면 echo 0이 찍히게 됩니다. 웹상으로는 1 과 0이 찍히는걸 확인했구요

 

그리고 php 에서 0 또는 1의 값을 안드로이드로 받아와  리턴하여 사용하도록 하고싶은데 echo 값을 받아오는게 도무지 감이안잡혀서 ㅠㅠ 질문을 올립니다

 

 


$uid = $_REQUEST['uid'];

 

$connect = mysql_connect("localhost","root","apmsetup");

mysql_select_db("door_lock",$connect);

mysql_query("set names utf8");

 

    $sql = "select count(*) FROM member WHERE id='$uid'";

$result = mysql_query($sql, $connect);

$count = mysql_fetch_array($result);

$num = $count[0];

 

$true = 1;

$false = 0;

 

 

if($num>0)

{

echo $true; //아이디 중복

}

else

{

echo $false; // 아이디 중복 아님

}

 

 

   // mysql_close($connect);

?>

 

=============================== 저의 php 쿼리문이구요 =============================================

 

 

overlap_bt.setOnClickListener(new OnClickListener() { // 중복체크 버튼을 눌렀을때

public void onClick(View v) {

try {

overlap = id_et.getText().toString();

String overlap_result = new overlap_post().execute(url_overlap, overlap).get();

 

if (id_et.getText().toString().getBytes().length <= 4) {

Toast.makeText(getApplicationContext(),"아이디를 제대로 입력해 주세요", Toast.LENGTH_SHORT).show();

 

if (overlap_result.equals("ok")) {

Toast.makeText(getApplicationContext(),"중복된 아이디 입니다", Toast.LENGTH_SHORT).show();

} else if (overlap_result.equals("no")) {

Toast.makeText(getApplicationContext(),"사용 가능한 아이디 입니다.", Toast.LENGTH_SHORT).show();

}

}

} catch (Exception e) {

Log.d(e.toString(), "error");

}

 

}

});

 
=============================== 중복체크 버튼을 눌렀을때 코드입니다. ===================================

 

public class overlap_post extends AsyncTask {

String Check = null;

@Override

protected String doInBackground(String... url) {

 

HttpPost request = new HttpPost(url[0]);

try {

Vector nameValue = new Vector();

nameValue.add(new BasicNameValuePair("uid", url[1]));

 

HttpEntity enty = new UrlEncodedFormEntity(nameValue, "utf-8");

request.setEntity(enty);

 

HttpClient client = new DefaultHttpClient();

 

HttpResponse res = client.execute(request);

HttpEntity entityResponse = res.getEntity();

 

InputStream im = entityResponse.getContent();

BufferedReader reader = new BufferedReader(new InputStreamReader(im, HTTP.UTF_8));

 

String total = null;

String tmp = null;

 

while ((tmp = reader.readLine()) != null) {

if (tmp != null) {

total += tmp;

}

}

im.close();

return total;

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

@Override

protected void onPostExecute(String value){

super.onPostExecute(value);

if(value.equals("1")){

Check = "ok";

}else{

Check = "no";

}

} 

}

 

======================= php에서 echo값을 받아와 처리하는 코드를 짜봤습니다.==============================

 

php echo값을 받아와 Check를 리턴하여 사용하고 싶은데

 

책 인터넷으로 공부하면서 해봐도 감이 안잡혀  질문을 올립니다.

 

부디 조언좀 주셨으면 감사하겠습니다 

 

익명사용자 님이 2015년 5월 20일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...