android - Can not send string to php file using namevaluepair -


i trying send string php script using namevaluepair. couldn't receive on other side. here code.

protected string doinbackground(string... args) {   arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(1);   namevaluepairs.add(new basicnamevaluepair("username",code ));   log.v("username", code);    defaulthttpclient httpclient = new defaulthttpclient(new basichttpparams());   httppost httppost = new httppost("http://192.168.42.21:8080/sellapp/menuitem.php");    // depends on web service   httppost.setheader("content-type", "application/json");    inputstream inputstream = null;   string result = null;     try {     httppost.setentity(new urlencodedformentity(namevaluepairs));     httpresponse response = httpclient.execute(httppost);     httpentity entity = response.getentity();      inputstream = entity.getcontent();     // json utf-8 default     bufferedreader reader = new bufferedreader(new inputstreamreader(inputstream, "utf-8"), 8);     stringbuilder sb = new stringbuilder();      string line = null;     while ((line = reader.readline()) != null)     {       sb.append(line + "\n");     }     result = sb.tostring();     } catch (exception e) {     // oops   }   {     try{if(inputstream != null)inputstream.close();}catch(exception squish {}   }   return result; } 

here want pass value in string code php script. php script is

$con = mysqli_connect(host,user,pass,db); $cst_id=$_request['username']; // $cst_id= 'cus02'; $sql = "   select   cust_code, segment_type, cust_name, cust_address, cust_payment_type, cust_credit_limit, cust_cr_balance  customer cust_code='".$cst_id."' ";  $res = mysqli_query($con,$sql);  $result = array(); while($row = mysqli_fetch_array($res)){   array_push(     $result,     [       'cust_id'=>$row[0],       'cust_seg'=>$row[1],       'cust_name'=>$row[2],       'cust_type'=>$row[3],       'cust_ad'=>$row[4],       'cust_cr'=>$row[5],       'cust_bl'=>$row[6]     ]   ); }  echo json_encode(array("result"=>$result));  mysqli_close($con); 

when giving value directly php works. through name/value pair returns null array result.

please me answer.i tried questions related it. didn't worked.

<?php       $con = mysqli_connect(host,user,pass,db);      $cst_id = $_post['username']; // --------- not $_request['username'];      // $cst_id= 'cus02';      $sql = "select  cust_code,segment_type,cust_name,cust_address,cust_payment_type,cust_credit_limit,cust_cr_balance customer cust_code='".$cst_id."' ";      $res = mysqli_query($con,$sql);       $result = array();     while($row = mysqli_fetch_array($res)){         array_push($result,             ['cust_id'=>$row[0],             'cust_seg'=>$row[1],             'cust_name'=>$row[2],             'cust_type'=>$row[3],             'cust_ad'=>$row[4],             'cust_cr'=>$row[5],             'cust_bl'=>$row[6]             ]);     }      //echo json_encode(array("result"=>$result));     echo json_encode($result);       mysqli_close($con);   ?> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -