2012-02-13 17 views
0

我剛剛開始連接Android應用程序與PHP 當我在本地wamp服務器上運行時,我的文件工作得很好 上傳到遠程服務器後,我想要什麼,但我正在仿真器上獲得一些額外的代碼。我想擺脫它 請幫助。 當我使用html文件在我的Chrome中調用同一個文件時,它也能正常工作。當我從Android應用程序調用我的PHP文件時,我收到一些額外的消息

這是我的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); 
?> 

我得到的輸出Here is a picture

+1

使用付費託管.. – Vamsi 2012-02-13 15:23:51

+0

請仔細閱讀SQL注入。 (這個評論可以自動發佈在每個有1個代表的用戶的php + mysql問題上嗎?) – CodeCaster 2012-02-13 15:27:24

回答

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);


希望它幫助。

+0

但是我還沒有返回所有在我的php中。 – Pratik 2012-02-13 15:24:36

+0

@ user865075然後你的主人這樣做。 – CodeCaster 2012-02-13 15:26:25

+0

當我在localhost上運行腳本時,沒有這樣的事情發生。當我上傳到遠程服務器時出現問題。這個東西不會出現,當我通過這個HTML文件http://pratik30.host56.com/usernamepass.html – Pratik 2012-02-13 15:26:33

相關問題