I have no errors or warnings in Eclipse and I'm completely new to Android Programming so I don't even know where to start with this.
My app is just a simple form that I need to post to a php script online.
Here's the bulk of my main Activity minus the imports.. I don't have it set up to do anything with return values or any of that, and TBH i don't even know what would happen if it did work other than the data would be in my DB.. but the PHP script is not even being called by my app at all.
Based on things I found in Google, I have tried -Adding Support Libraries -Changing the target sdk version from 19 to 18
Please, what am I doing wrong?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apply);
subm = (Button) findViewById(R.id.button1);
fname = (EditText) findViewById(R.id.editText1);
lname = (EditText) findViewById(R.id.editText2);
addr = (EditText) findViewById(R.id.editText3);
city = (EditText) findViewById(R.id.editText4);
state = (EditText) findViewById(R.id.editText5);
zip = (EditText) findViewById(R.id.editText6);
phone = (EditText) findViewById(R.id.editText7);
dob = (EditText) findViewById(R.id.editText8);
email = (EditText) findViewById(R.id.editText9);
ssn = (EditText) findViewById(R.id.editText10);
subm.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
String httpsURL = "https://example.com/apis/submit_credit_application.php";
String query = "fname="+URLEncoder.encode(fname.getText().toString(),"UTF-8");
query += "&lname="+URLEncoder.encode(lname.getText().toString(),"UTF-8");
query += "&addr="+URLEncoder.encode(addr.getText().toString(),"UTF-8");
query += "&city="+URLEncoder.encode(city.getText().toString(),"UTF-8");
query += "&state="+URLEncoder.encode(state.getText().toString(),"UTF-8");
query += "&zip="+URLEncoder.encode(zip.getText().toString(),"UTF-8");
query += "&phone="+URLEncoder.encode(phone.getText().toString(),"UTF-8");
query += "&dob="+URLEncoder.encode(dob.getText().toString(),"UTF-8");
query += "&email="+URLEncoder.encode(email.getText().toString(),"UTF-8");
query += "&ssn="+URLEncoder.encode(ssn.getText().toString(),"UTF-8");
URL myurl = new URL(httpsURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-length", String.valueOf(query.length()));
con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
con.setDoOutput(true);
con.setDoInput(true);
DataOutputStream output = new DataOutputStream(con.getOutputStream());
output.writeBytes(query);
output.close();
}catch(IOException e){
Toast.makeText(
getApplicationContext(),
(CharSequence) e,
Toast.LENGTH_LONG
).show();
}
}
});
}