mardi 24 février 2015

eclipse android pass a java value to php by using HTTP



I want to pass the variable q from java to php.



String q = "select author from books where 1";
try{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://ift.tt/1BOeYyd"+q);
//"http://10.0.2.2/tut.php", http://ift.tt/1Dlqn6u
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
e.printStackTrace();
System.out.println("Exception 1 caught");
}


However, the php file cannot get the value from java(php connected to mysql correctly).


php coding:



<?php
$con=mysql_connect("XXX.XXX","XX","XXX");
mysql_select_db("XX",$con);

$st = $_GET['qy'];
$r = mysql_query("$st");

while($row=mysql_fetch_array($r))
{
$out[]=$row;
}

print(json_encode($out));
mysql_close($con);
?>


I found that if I just pass the table name to php, it works. But if the passing variable become longer, it went to caught one. How can I fix this? How about passing more than one variable to php (i.e. mysql_query("select $_GET['col'] from $_GET['table'] where $_GET['condition']");)?




Aucun commentaire:

Enregistrer un commentaire