简体   繁体   English

当我从android应用程序调用我的php文件时,我收到一些额外的消息

[英]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.

相关问题 当我从PHP / Apache而不是PHP / CLI或直接从pdftk调用pdftk时,为什么会出现SegFault - Why am I getting a SegFault when I call pdftk from PHP/Apache but not PHP/CLI or directly 为什么我在上传文件时在我的日志中收到“call to member function null”? - Why am I getting a “call to member function null” in my logs when file uploading? 从Angular2应用发布到PHP时为什么会出现404错误? - Why am I getting a 404 error when I post from an Angular2 app to PHP? 使用Android Volley发布到我的php时,为什么会出现foreach错误? - why am I getting foreach error when posting with Android Volley to my php? 当我尝试将PHP应用程序部署到Google App Engine时,为什么突然出现400错误? - When I try to deploy my PHP application to Google App Engine, why am I suddenly getting a 400 error? 从我的GIT存储库获得Laravel项目后,为什么会收到此错误消息? - Why am I getting this error message after I obtained my Laravel project from my GIT repository? 为什么我不能从该php文件中获取XML输出? - Why am I not getting XML output from this php file? 尝试添加额外语句以运行查询时,我收到 MariaDb 错误 - I am getting an error from MariaDb when trying to Add extra statement to working the query 为什么我从可变范围函数中获得了额外的价值? - Why i am getting extra values from variable scope function? 当我在终端中输入 php artisan serve 时,我收到“需要 Mcrypt PHP 扩展” - I am getting "Mcrypt PHP extension required" when I type php artisan serve in my terminal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM