简体   繁体   中英

How to display data sent from android app to a php on an html page?

I am really confused about how to send data from my android app to a website. I am thinking of using php to get data from android and send data to the html page. I am aware of sending data through php to a mysql server. I am unsure about the php and html file that I have to develop here. I need the data to be displayed in some textbox in my html page.

Is there any other way to do this?

I am not sure what you mean by sending data to HTML page from php, html can not recieve data. Instead you can use a php page to do it.

Android code:

HttpPost httppost = new HttpPost("PHP_PAGE_ADDRESS");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("data", "abc"));
nameValuePairs.add(new BasicNameValuePair("data1", "def"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);

PHP Code:

<?php
$data =$_GET['data'];
$data1 = $_GET['data1'];
?>
<form>
Data: <input type="text" name="firstname" value = <?php echo $data; ?> ><br>
Data1: <input type="text" name="firstname" value = <?php echo $data1; ?> >
</form>

Hope this helps.

Try to send your data in json format. Actually i am not aware of android app. But i think it is possible to send data in json format and you can easily receive in php by

json_decode($encoded_json_var);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM