I'm trying to make an android app which communicates with a php file/database.
I don't get it working, I'm completely new at this kind of android programming.
I already got this from a tutorial:
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
name = userInput.getText().toString();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.test.com/register.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("name", name));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
PHP CODE:
// including database connection
$name= $_POST['name'];
$register= "INSERT INTO Users (Name, Level) VALUES(".$name.", 1)";
$result = $conn->prepare($register);
$result->execute();
When I startup my app it instantly crashes.
What I'm doing wrong?
Does this code still work?
Did i forgot something?