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条)

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数