I have an android app, i need to submit a user inputted name (example- paul,john) to a mysql database. To do this i have a simple php file that gets the name using a get method then inserts the name to the mysql table, this tested successfully in a my browser both on a computer and the android emulator browser. however its not working within the android app. App has a submit button, when clicked it should create the link,( example- http://10.0.2.2/project2/signup.php?name=john" ) and open a HttpURLConnection to add the name to the database using the php script. No matter what i do i cannot seem to get the inputted name to be inserted into my database.
public void sign_up(View view)
{
EditText newuserET = (EditText) findViewById(R.id.newuserET);
String editTextValue = newuserET.getText().toString();
//Toast.makeText(this, "Signing up...", Toast.LENGTH_SHORT).show();
String link;
String data;
BufferedReader bufferedReader;
String result;
try {
// data = "?name=" + URLEncoder.encode(fullName, "UTF-8");
link = "http://10.0.2.2/project2/signup.php?name=" + editTextValue;
//Toast.makeText(this, link, Toast.LENGTH_SHORT).show();
URL url = new URL(link);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setDoOutput( true );
// return result;
} catch (Exception e)
{
// return new String("Exception: " + e.getMessage());
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
I also added the following in the Android manifests- outside the application scope not inside
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />