I'm trying post data on PHP server through HTML using this HTML code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form action="http://localhost:/" method="post">
<input type="hidden" value="Expence Description" id="ExpenceDescription" name="ExpenceDescription" />
<input type="hidden" value="DA, TA, Others" id="Descriptions" name="Descriptions" />
<input type="hidden" value="100, 101, 102" id="Amounts" name="Amounts" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
This is my android code:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("ExpenceDescription", "'" + expenses_head + "'"));
nameValuePairs.add(new BasicNameValuePair("Descriptions", "'" + total_desc + "'"));
nameValuePairs.add(new BasicNameValuePair("Amounts", "'" + total_amount + "'"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
//HttpResponse response = httpclient.execute(httppost);
StatusLine statusLine = response.getStatusLine();
The problem is that I'm getting internal server error 500 on response line.
You would need to specify the php file in the action.. for example if your file which listens to the post parameters is called server.php then in form action define as below, assuming both the; this html page and php file reside in the same webserver directory otherwise specify the url for ur php file
<form action="server.php" method="post">
<input type="hidden" value="Expence Description" id="ExpenceDescription" name="ExpenceDescription" />
<input type="hidden" value="DA, TA, Others" id="Descriptions" name="Descriptions" />
<input type="hidden" value="100, 101, 102" id="Amounts" name="Amounts" />
<input type="submit" value="Submit" />
</form>
You need a language independent data interchange format like JSON to transfer data from Android to PHP and vice versa.
In PHP you can format your data in json with json_encode and json_decode and in Android you can manage Json with JSONObject and JSONArray