How can I get data from a column and put it in a TextView? ? I tried this way:
private static final String REGISTER_URL="http://localhost/teste.php";
private void register(String nome){
String urlSuffix = "?getinfo=" + nome;
class RegisterUser extends AsyncTask<String, Void, String> {
TextView telefone = findViewById(R.id.textView6);
@Override
protected String doInBackground(String... params) {
String s = params[0];
BufferedReader bufferReader=null;
try {
URL url=new URL(REGISTER_URL+s);
HttpURLConnection con=(HttpURLConnection)url.openConnection();
bufferReader=new BufferedReader(new InputStreamReader(con.getInputStream()));
String result;
result=bufferReader.readLine();
telefone.setText(result);
return result;
}catch (Exception e){
return null;
}
}
}
RegisterUser ur=new RegisterUser();
ur.execute(urlSuffix);
}
PHP:
$nome=$_POST['getInfo'];
$sql = "SELECT Telefone FROM Usuarios WHERE Nome='$nome'";
$result = mysqli_query($sql);
if ($result !== false){
$result = $conn->query($sql);
$row = $result->fetch_array(MYSQLI_NUM);
echo $row[0];
}else{
echo "ERROR";
}