2014-02-13 2 views
1

phpmyadmin 데이터베이스에서 특정 값을 검색하려고합니다. 행을 retieve하려면 to=$username mytasksend 테이블에서. 하지만 변수를 echo 할 때 출력이 나오지 않습니다. 내가 무엇을해야하나요?안드로이드에서 php로 값을 얻을 수없는 이유는 무엇입니까?

여기 내 자바 파일

try{ 
    HttpClient httpclient3 = new DefaultHttpClient(); 
    HttpPost httppost3 = new HttpPost("http://10.0.2.2:80/selection.php"); 
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
    nameValuePairs.add(new BasicNameValuePair("to",id)); 
    Log.w("aaaaaaa",""+nameValuePairs); 
    httppost3.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
    HttpResponse response = httpclient3.execute(httppost3); 
    HttpEntity entity = response.getEntity(); 
    is = entity.getContent(); 

    Log.e("log_tag", "connection success "); 
} 

답변

0

쿼리에서 작은 따옴표 아래 $username을 포장하려고 내 PHP 파일

<?php 
mysql_connect ("localhost","root",""); 
mysql_select_db("taskmanager"); 

$username= (isset($_POST['to'])) ? $_POST['to'] : ''; 
$q=mysql_query("SELECT `tasksentid` FROM `mytasksend` where `to` = $username")    or die(mysql_error()); 

$output=array(); 
    while($e=mysql_fetch_assoc($q)) 
    $output[]=$e; 
print (json_encode($output)); 
mysql_close(); 

?> 

그리고 여기.

"SELECT `tasksentid` FROM `mytasksend` where `to` = '$username'" 
+1

감사합니다. – user3256145

0

저는 안드로이드 전문가가 아니지만 PHP를보고 있으므로 $ username을 따옴표로 묶어서는 안됩니까? 또한 $ _POST를 통해 들어오는 모든 데이터의 유효성을 검사하거나 정리해야합니다.

+0

감사합니다. – user3256145

관련 문제