0
EclipseからPHPへのデータベース接続を構築するコードですが、データベースに空の文字列が格納されています。誰かが私が途中で作ったかもしれない間違いを指摘できますか?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
どのようなエラーがありますか? – Hend
最低でも 'localhost'ではなくコンピュータのIPアドレスを使う必要があります。 – jprofitt
チェックhttp://fahmirahman.wordpress.com/2011/04/21/connection-between-php-server-and-android-client-using-http-and-json/ –