I have a project where I\'m supposed to send data such as integers, floats and text strings from an android app to a web database. However I don\'t have the first clue on how to
In phone you can use following code (no tested):
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List nameValuePairs = new ArrayList(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "Hi"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
In PHP you can do something like this:
";
echo "String data: {$_POST['stringdata']}
";
//you can implement database logic here too (insert data to database)
} else {
echo "You can't see this page without submitting the data.";
}
?>