dongxie8906 2014-02-13 02:01
浏览 72
已采纳

为什么我不能从android中获取PHP的值?

I am trying to retrieve specific values from phpmyadmin database.I want to retieve the row where to=$username from mytasksend table. But when i echo the variable i don't get any output. What am i supposed to do?

Here's my php file

<?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();

?>

and here's my java file

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 ");
}

展开全部

  • 写回答

2条回答 默认 最新

  • dongzi3805 2014-02-13 02:06
    关注

    Try wrapping the $username under single quotes in the query.

    "SELECT `tasksentid` FROM `mytasksend` where `to` = '$username'"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部