【发布时间】: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
【问题讨论】:
-
您至少需要使用计算机的 IP 地址,而不是
localhost。
标签: php android database eclipse wamp