【问题标题】:Building a connection from Eclipse to a PHP database file建立从 Eclipse 到 PHP 数据库文件的连接
【发布时间】:2012-01-12 03:10:01
【问题描述】:

这是我的代码,用于构建从 Eclipse 到包含我的数据库连接的 PHP 文件的连接,但它在数据库中存储了一个空字符串。谁能指出我在此过程中可能犯的错误?

 add.setOnClickListener(new View.OnClickListener() {


           public void onClick(View arg0) {
           Intent add = new Intent(addUser.this, FavUser.class);
           startActivity(add);

           InputStream is = null;


           EditText txtSearch = (EditText) findViewById(R.id.txtSearch);
           String strSearch = txtSearch.getText().toString();

           List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
           nameValuePairs.add(new BasicNameValuePair(strSearch, strSearch));

           try {

               // Add your data

               HttpClient httpclient = new DefaultHttpClient();
               HttpPost httppost = new HttpPost("http://10.0.2.2/connecttodb.php");

               httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

               // Execute HTTP Post Request
               HttpResponse response = httpclient.execute(httppost);
               HttpEntity entity = response.getEntity();
              is = entity.getContent();

           } catch (IOException e) {
              Log.e("Log_tag", "error in http connection" +e.toString());
           }
           // convert reposonse to string

【问题讨论】:

标签: php android database eclipse wamp


【解决方案1】:

代码本身看起来不错,但如果您提供任何错误消息会更好。无论如何,我建议检查您的 IP 地址。它看起来像您的路由器的 IP,寻址到您的服务器。转到谷歌并输入“我的IP地址是什么”并将其替换为您正在使用的地址;如果它不同。另外不要忘记在更改代码后将端口从路由器转发到您的服务器。

【讨论】:

    猜你喜欢
    • 2015-05-30
    • 2016-12-15
    • 1970-01-01
    • 2015-02-20
    • 2016-08-03
    • 1970-01-01
    • 1970-01-01
    • 2016-07-08
    • 1970-01-01
    相关资源
    最近更新 更多