dongxie8906 2014-02-13 10: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 10:06
    关注

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

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?