Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我不能从android中获取php值?_Php_Android_Mysql - Fatal编程技术网

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

为什么我不能从android中获取php值?,php,android,mysql,Php,Android,Mysql,我正在尝试从phpmyadmin数据库中检索特定值。我想从mytasksend表中重新筛选where to=$username行。 但是当我回显变量时,我没有得到任何输出。 我该怎么办 这是我的php文件 <?php mysql_connect ("localhost","root",""); mysql_select_db("taskmanager"); $username= (isset($_POST['to'])) ? $_POST['to'] : ''; $q=mysql_que

我正在尝试从phpmyadmin数据库中检索特定值。我想从mytasksend表中重新筛选where to=$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();

?>
这是我的java文件

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 ");
}
尝试将$username包装在查询中的单引号下

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

我不是android专家,但看看你的PHP,你不应该在$username附近加引号吗?您还应该真正验证/清除通过$\u POST发送的任何数据