I am trying to insert some values into a MySQL-database using PHP. I am fairly certain that my android code is correct, but I have very limited understanding of PHP. Am I doing something obvious wrong?
<?
$databasehost = "MyIPAdress:port";
$databasename = "databaseIWant";
$databaseusername = "UserWithPerms";
$databasepassword = "CorrectPassword";
$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
$email = $_POST['email'];
$password = $_POST['password'];
$school = $_POST['school'];
$sql = "INSERT INTO users(username, password, school) VALUES ('$email', '$password', '$school');
$query_exec = mysql_query($sql) or die(mysql_error());
mysql_close();
?>
Here is the android code as well: (Java)
When a user registers this method gets called:
private void RegisterNewUser(String username, String password) {
RegisterUserOnNetwork regUser = new RegisterUserOnNetwork();
regUser.execute(username, password);
}
class RegisterUserOnNetwork extends AsyncTask<String, String, String> {
private Exception exception;
protected String doInBackground(String... strings) {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("email", strings[0]));
nameValuePairs.add(new BasicNameValuePair("password", strings[1]));
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://IpAdress/RegisterUser.php");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
Log.e("RESULT", EntityUtils.toString(httpEntity) + "l");
return "Gebruiker suksesvol geskep!";
} catch (Exception e) {
e.printStackTrace();
return "Bediener kon nie bereik word nie.";
}
}
}
"to end the$sqlstring is just a typo and correct in your PHP code?