[英]I am getting some extra message when i call my php file from android app
I have just started connecting android app with php My file works very fine when i run on local wamp server After uploading on remote server , I am getting what i want but i am getting some extra code on my emulator. 我刚刚开始用php连接android app。当我在本地wamp服务器上运行时,我的文件工作得很好。在远程服务器上上传后,我得到了我想要的东西,但是我在模拟器上得到了一些额外的代码。 I want to get rid of it Please help.
我想摆脱它,请帮助。 When i call the same file in my chrome using an html file then also it works fine.
当我使用html文件在Chrome中调用同一文件时,它也可以正常工作。
Here is code of my android app 这是我的Android应用程序的代码
public class LoginActivity extends Activity {
HttpClient hc;
HttpPost hp;
List<NameValuePair> nvp;
HttpResponse hr;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText username=(EditText) findViewById(R.id.username);
final EditText password=(EditText) findViewById(R.id.password);
Button b=(Button) findViewById(R.id.register);
final TextView res=(TextView) findViewById(R.id.textView3);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
// String result="Username: "+username.getText().toString()+"\n"+"Password: "+password.getText().toString();
//res.setText(result);
try
{
hc=new DefaultHttpClient();
hp=new HttpPost("http://pratik30.host56.com/insertquery.php");
nvp=new ArrayList<NameValuePair>(2);
nvp.add(newBasicNameValuePair("username", username.getText().toString()));
nvp.add(new BasicNameValuePair("password", password.getText().toString()));
hp.setEntity(new UrlEncodedFormEntity(nvp));
//hr=hc.execute(hp);
ResponseHandler<String> rs= new BasicResponseHandler();
String r=hc.execute(hp,rs);
res.setText(r);
}
catch(Exception e)
{
res.setText(e.getLocalizedMessage());
}
}
});
}
} }
Here is the php file 这是PHP文件
<?php
$dbc=mysqli_connect('localhost','root','mypassword','pratik') or die('Error connecting to mysql server');
$user=$_POST['username'];
$pass=$_POST['password'];
echo $user;
echo $pass;
$query = "Insert into users values ('$user','$pass');";
$result=mysqli_query($dbc,$query) or die('Error querying database');
mysqli_close($dbc);
?>
Here is a picture of the output I am getting. 这是我得到的输出的图片 。
Your php returns the following you have to remove it from there: 您的php返回以下内容,您必须将其从此处删除:
<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
you're setting the whole result text into your TextView res.setText(r);
您要将整个结果文本设置为TextView中的
res.setText(r);
hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.