I have an application that get a very simple data from my free host (I uploaded a php file in my host), and show that in a textview in my application. The data that my app get from host is a very simple (a text that my php file send to my app is like the result of this code : print "user exist"; but with that "user exist" my application shows a HTML tag with it, I think it is because of my Host, but how can I delete that HTML tag and just get the result of my php file to my android application. the image : http://8pic.ir/images/5i9y87e8xp9wocu1qaui.png I don't know from where (android cod or php in my host) the problem can resove than I copy both of them here :
my HTML code :
<?php
$con = mysql_connect("mysql14.000webhost.com", "mohad", "229");
mysql_select_db("mydb", $con);
$user = $_POST['username'];
$result = mysql_query("select Password from tbl_users where Username = '$user' ");
$row = mysql_fetch_array($result);
if($row[0]){print "user exist";}else print "no user";
mysql_close($con);
?>
my android code (Main activity) :
public class Main extends Activity {
public static String netdata;
private Button btnGet;
private TextView txtShowdata;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtShowdata = (TextView) findViewById(R.id.txtShowdata);
btnGet = (Button) findViewById(R.id.btnGet);
btnGet.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new Getdata().execute("http://mohad.webuda.com/test.php", "mohad");
txtShowdata.setText(netdata);
}
});
}// end onCreat()
}// end Class
and here is myAsync class :
public class Getdata extends AsyncTask <Object, Object, Object>{
StringBuilder strBuilder;
@Override
protected Object doInBackground(Object... params) {
try{
URL url_mylink = new URL(params[0].toString());
URLConnection url_connect = url_mylink.openConnection();
// Send to host
String sendingdata = URLEncoder.encode("username", "UTF8") +"="+ URLEncoder.encode(params[1].toString(), "UTF8");
url_connect.setDoOutput(true);
OutputStreamWriter osw = new OutputStreamWriter(url_connect.getOutputStream());
osw.write(sendingdata);
osw.flush();
// Get from host
InputStreamReader isr = new InputStreamReader(url_connect.getInputStream());
BufferedReader bufR = new BufferedReader(isr);
String temp_line = null;
strBuilder = new StringBuilder();
while((temp_line=bufR.readLine()) != null){
strBuilder.append(temp_line);
}
}catch(Exception e){ e.printStackTrace();}
return strBuilder;
}// end doInBackground()
@Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
Main.netdata = result.toString();
}// end onPostExecute()
}// end Class