Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to echo incoming data (from an Android app) in PHP file

So, I want to display a message sent from an android app in a PHP file. Right now, I am able to do so by placing the message into an HTML file and then displaying the contents of the HTML file. Is there any way I can do this without the HTML file? i.e. just echoing the message right away? Here is the PHP code I am using now:

<?php
// get the "message" variable from the post request
// this is the data coming from the Android app
$message=$_POST["message"]; 
// specify the file where we will save the contents of the variable message
$filename="androidmessages.html";
// write (append) the data to the file
file_put_contents($filename,$message."<br />",FILE_APPEND);
// load the contents of the file to a variable
$androidmessages=file_get_contents($filename);
// display the contents of the variable (which has the contents of the file)
echo $androidmessages;
?>

I have tried just echo $message; but it doesn't work and when opened, the PHP file gives this error Notice: Undefined index: message in C:\xampp\htdocs\testPHP.php on line 3

Any ideas on how to do this? Thanks guys.

Comments