- Anda perlu memprogram beberapa logika sisi server (halaman PHP yang menerima parameter key=value dengan metode POST atau GET)
- Lalu jika data sudah terverifikasi simpan ke database
- Di ponsel Anda harus mengimplementasikan kelas HttpClient dan HttpPost untuk POST data ini ke halaman PHP
Di telepon Anda dapat menggunakan kode berikut (tidak diuji):
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<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(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
}
}
Di PHP Anda dapat melakukan sesuatu seperti ini:
<?php
//Check whether the data has been submitted
if (isset($_POST['id'] && isset($_POST['stringdata'])) ) {
//Let's now print out the received values in the browser
echo "Id: {$_POST['id']}<br />";
echo "String data: {$_POST['stringdata']}<br />";
//you can implement database logic here too (insert data to database)
} else {
echo "You can't see this page without submitting the data.";
}
?>