0

Android アプリと php の接続を開始したところです。ローカルの wamp サーバーで実行すると、ファイルが非常に正常に動作します。リモート サーバーにアップロードした後、必要なものを取得していますが、エミュレーターで余分なコードを取得しています。消したいので助けてください。HTMLファイルを使用してChromeで同じファイルを呼び出すと、正常に動作します。

これが私の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());   
            }
        }
    });
}

}

ここに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);
?>

ここに私が得ている出力の写真があります。

4

1 に答える 1

0

あなたの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 -->

結果テキスト全体を TextView に設定していますres.setText(r);


それが役に立てば幸い。

于 2012-02-13T15:22:21.870 に答える