I was searching for a way to send a data from android app to PHP and display it in an HTML. I saw the same question and try it How to display data sent from android app to a php on an html page?. But now it does not work.
My android app feature is to input firstname, lastname and address. After completing the input, click button save and then redirect to the web browser and display the input details. This is what I've tried.
Android App
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
savebtn = findViewById(R.id.savebtn);
editTextFName = findViewById(R.id.editTextFName);
editTextLName = findViewById(R.id.editTextLName);
editTextAddress = findViewById(R.id.editTextAddress);
savebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String val_Fname = editTextFName.getText().toString();
String val_Lname = editTextLName.getText().toString();
String val_Addr = editTextAddress.getText().toString();
HttpPost httppost = new HttpPost("http://xxx.xxx.xxx.xxx/webdisplay/index.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
try{
nameValuePairs.add(new BasicNameValuePair("android_Fname", val_Fname);
nameValuePairs.add(new BasicNameValuePair("android_Lname", val_Lname));
nameValuePairs.add(new BasicNameValuePair("android_Addr", val_Addr));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
}catch(Exception e){
Log.e("log_tag", "Error"+e.toString());
}
redirectTo("http://xxx.xxx.xxx.xxx/webdisplay/index.php");
}
});
}
PHP
<?php
$dataFname = $_GET['android_Fname'];
$dataLname = $_GET['android_Lname'];
$dataAddr = $_GET['android_Addr'];
?>
<html>
<body>
<div>
<?php echo $dataFname; ?>
<?php echo $dataLname; ?>
<?php echo $dataAddr; ?>
</div>
</body>
</html>
and then redirect to the web browser and display the input details.That is not possible with another app or with another call to the same url as then you get the html form elements empty just like when you called it for the first time. (Why didn't you tell?). No. Your page is inHttpResponse response. You could display it in a WebView.$_GETinstead of$_POST$_POSTbut it is still empty no data is showing