I have downloaded xamp server and I have installed it. I have created a database named "blogDB" and I have created a table with name LoginTable which has UID, username, password, status as columns. Now from my Android Application, I need to enter values to the database table created manually in the server. I am sending an Http Post request. I am not getting which url should I pass to connect to database. Currently I am having the following code:
public void onClickLogin(View view) {
// get The User name and Password
enteredUserName = userName.getText().toString();
enteredPassword = password.getText().toString();
new ServerOperation().execute();
}
public class ServerOperation extends AsyncTask {
@Override
protected Object doInBackground(Object[] params) {
// Get user defined values
enteredUserName = userName.getText().toString();
enteredPassword = password.getText().toString();
// Create data variable for sent values to server
String data = null;
try {
data = URLEncoder.encode("name", "UTF-8")
+ "=" + URLEncoder.encode(enteredUserName, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
data += "&" + URLEncoder.encode("email", "UTF-8") + "="
+ URLEncoder.encode(enteredPassword, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String text = "";
BufferedReader reader=null;
// Send data
try
{
// Defined URL where to send data
URL url = new URL("http://10.0.2.2/phpMyAdmin/tbl_addfield.php");
// Send POST data request
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write( data );
wr.flush();
// Get the server response
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while((line = reader.readLine()) != null)
{
// Append server response in string
sb.append(line + "\n");
}
text = sb.toString();
}
catch(Exception ex) {
Log.e("iFocus", ""+ex);
}
try
{
}
finally
{
try
{
reader.close();
}
catch(Exception ex) {}
}
// Show response on activity
// content.setText( text );
return null;
}
}
Please let me know what url should I use to connect to my database and how to enter data into the table. I am struggling from long time. Please help me come out of this problem.