2014-12-03 2 views
0

이것은 xamp server.Here를 사용하여 android-php-mysql 연결을 기반으로하는 간단한 프로젝트이며, 서버 데이터베이스에서 성공적으로 업데이트하고 쿼리를 업데이트하려고합니다. 내 프로그램의 상태가 작동하지 않는다면, 나는 무엇을 할 것인가 ?? 제발 도와주세요. 여기 제 코드가 있습니다 !! 는내부 조건이 프로그램 내부에서 작동하지 않는 경우

btt.setOnClickListener(new View.OnClickListener() { 

    @Override 
    public void onClick(View v) { 


    try{ 
      httpclient=new DefaultHttpClient(); 
      httppost= new HttpPost("http://192.168.0.45/doctorphp/status.php"); // make sure the url is correct. 
      //add your data 
      nameValuePairs = new ArrayList<NameValuePair>(1); 
      // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar, 
      nameValuePairs.add(new BasicNameValuePair("date",Datetxt.getText().toString().trim())); // $Edittext_value = $_POST['Edittext_value']; 

      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
      ResponseHandler<String> responseHandler = new BasicResponseHandler(); 
      final String response = httpclient.execute(httppost, responseHandler); 
      System.out.println("Response : " + response); 
     runOnUiThread(new Runnable() { 
      public void run() { 
        tvView.setText("Response from PHP : " + response); 


      } }); 

      if(response.equalsIgnoreCase("Granted")){ 
       runOnUiThread(new Runnable() { 
        public void run() { 
         Toast.makeText(UserPage.this,"Granted successfully", Toast.LENGTH_SHORT).show(); 

        } 
       }); 
       Intent intent=new Intent(UserPage.this, token.class); 
       startActivity(intent); 
      } 
      else{ 
        showAlert();  
      } 
     } 
     catch(Exception e){ 

      System.out.println("Exception : " + e.getMessage()); 
      Toast.makeText(getApplicationContext(),"Error:"+e.toString(), Toast.LENGTH_LONG).show(); 
     } 



    } 
});   
+1

디버깅 해 본 적이 있습니까? –

+1

'응답'에 뭐가 들었습니까 ?? –

답변

0

if(response.toString().trim().equalsIgnoreCase("Granted")){ 
    runOnUiThread(new Runnable() { 
     public void run() { 
      Toast.makeText(UserPage.this,"Granted successfully", Toast.LENGTH_SHORT).show(); 

     } 
    }); 
    Intent intent=new Intent(UserPage.this, token.class); 
    startActivity(intent); 
} 
+0

죄송합니다 ... 죄송합니다 ... 작동하지 않는다면 블록이 실행되지 않으면 내 프로그램 블록을 다른 곳으로 직접 보냅니다. –

+0

수정 된 답변 확인 –

+1

먼저 응답 내용을 확인해야합니다. – Darpan

0

이 공공 정적 문자열 응답을 = ""초기화하십시오 작동 this..hope하려고 사전에 감사합니다;

응답 = httpclient.execute (httppost, responseHandler);

관련 문제