2

I have a php script on a local server that creates and manages an SQL table. I am able to create the table and database through my android app but I am having trouble figuring out how to send data to the php file. I want to send a string so that I can sort and pick the values to return to my app.

How do I change my php and android code so that I can get entries in the table between 2 dates?

Here is some of my Android code:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.0.3/xampp/information.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();

The beginning of information.php script is setup like this:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("data",$con);

How do I send a string from Android to the php file?

0

1 Answer 1

2

You should try using $_POST variables. So your HttpPost object would be initialized like this:

HttpPost httppost = new HttpPost("http://10.0.0.3/xampp/information.php?info="+nameValuePairs);

Then, in your PHP, just check to see if the variable info is set, and then process it if it is.

if(isset(_$POST['info']))
  //process data

This would, of course, requiring some formatting of nameValuePairs so that it is a valid URL, but it forces everything into one variable which you can easily check in your PHP.

Sign up to request clarification or add additional context in comments.

1 Comment

It is easy but it may be create problem when the name valuepairs have ;arge number of data.At that time it gives the error like "Request-URI Too Large".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.