I have made a php file that posts the data to the db and using the android I should post some text. The problem is, When I submit the text A new data gets added to the database, but it's blank data. No numbers, text, etc ..
this is my code:
public class mainactivity extends Activity {
EditText edittext1;
EditText edittext2;
EditText edittext3;
String name;
String nationality;
String sex;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edittext1 = (EditText) findViewById(R.id.editText1);
edittext2 = (EditText) findViewById(R.id.editText2);
edittext3 = (EditText) findViewById(R.id.editText3);
name = edittext1.getText().toString();
sex = edittext3.getText().toString();
nationality = edittext3.getText().toString();
Button done = (Button) findViewById(R.id.button1);
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
new Thread(new Runnable() {
@Override
public void run() {
DefaultHttpClient httpclient= new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.xxx.com/thescript.php");
Log.e("done 1st","its here");
try
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", name));
nameValuePairs.add(new BasicNameValuePair("sex", sex));
nameValuePairs.add(new BasicNameValuePair("nationality", nationality));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.e("done", String.valueOf(response));
}
catch(Exception e)
{
Log.e("didn't work", "hardluck");
e.printStackTrace();
}
}
}).start();
}
});
}
}
logcat
09-24 20:13:50.302: E/done 1st(28390): its here
09-24 20:13:51.442: E/done(28390): org.apache.http.message.BasicHttpResponse@416c1b80
this is my current db,maybe the problem is in it
CREATE TABLE `people` (
`name` varchar(20) COLLATE latin1_general_ci NOT NULL,
`sex` varchar(10) COLLATE latin1_general_ci NOT NULL,
`nationality` varchar(15) COLLATE latin1_general_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;