php - how to send a post parameter in JsonArrayRequest -
im trying send post parameter php file
<?php $sid = $_post['sid']; ini_set( 'error_reporting', e_all ); ini_set( 'display_errors', true ); include 'dbconfig.php'; //include 'sql.php'; //include 'pass.php'; ob_start(); include 'pass.php'; ob_end_clean() ; /* if($_server['request_method']=='post'){*/ // create connection $conn = new mysqli($servername, $username, $password, $dbname); mysqli_set_charset($conn,'utf8'); if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "select * lime_questions sid=$sid"; $result = $conn->query($sql); if ($result->num_rows >0) { // output data of each row while($row[] = $result->fetch_assoc()) { $tem = $row; $json = json_encode($tem, json_unescaped_unicode); } } else { echo "0 results"; } $data= strip_tags ($json); echo str_replace('success','',$data); //$encoded=json_decode($json); //print_r($encoded); //echo json_last_error_msg(); $conn->close(); ?>
the problem $sid variable must sent jsonarrayrequest parse received , java code : im using jsonarrayrequest data server app
public void loaddata() { bundle extras = getintent().getextras(); //sid = extras.getstring(login.key_url); sid="1994"; jsonarrayrequest newsreq1 = new jsonarrayrequest(url1, new response.listener<jsonarray>() { @override public void onresponse(jsonarray response) { (int = 0; < response.length(); i++) { try { jsonobject obj = response.getjsonobject(i); string sqid = obj.getstring("sid"); string gid = obj.getstring("gid"); string id = obj.getstring("qid"); string q = obj.getstring("question"); string t = obj.getstring("type"); insertintodb(sqid, gid, id, q, t); test.settext(q); newsquestions question = new newsquestions(id, q, t); // adding question questions array questionslist.add(question); } catch (exception e) { system.out.println(e.getmessage()); } { } } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { system.out.println(error.getmessage()); }} ) { @override protected map<string, string> getparams() throws authfailureerror { map<string, string> params = new hashmap<string, string> (); params.put(key_url,sid); return params; } @override public int getmethod() { try { getparams(); } catch (authfailureerror authfailureerror) { authfailureerror.printstacktrace(); } return super.getmethod(); } };
my question how send sid parameter android app php m=file
try using post method request :
jsonarrayrequest req = new jsonarrayrequest(request.method.post, strurl, new jsonobject(mrequestparams), new response.listener<jsonarray>() { @override public void onresponse(jsonarray response) { try { //here receive response } catch (jsonexception e) { e.printstacktrace(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { //do want on error } });
Comments
Post a Comment