trying to send data using POST from android to sql
I am trying to POST data from my android to my sql server
This is in my android application
List<NameValuePair> nameValuePairs = new ArrayList<NameVa开发者_开发知识库luePair>();
nameValuePairs.add(new BasicNameValuePair("firstName",value));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
This is my php
$firstName = $_POST["firstName"];
$sql = "SELECT firstName FROM `colleague` WHERE `lastName`
LIKE '%$firstName%' LIMIT 0, 5 ";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) $output[] = $row['firstName'];
echo implode("<br/>",$output);
print(json_encode($output));
But this now selects the first five rows .. it does not receive anything in $firstName = $_POST["firstName"]; ??
php Notice
Undefined index: firstName in C:\xampp\htdocs\
http declaration
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.1/Search.php");
$firstName = $_POST['firstName'];
try single quotations. do you have spaces in the value for $firstName? if it is encoded, do decoding in php. Example if you have Your(space)Name
then encoded form will be Your+Name
, if you dont decode it the query has encoded value for $firstName
. Use urldecode($_POST['firstName'])
to decode the encoded url content
精彩评论