我正在开发一个Android项目,因为我需要将登录详细信息发送到在线数据库。我完成了我的代码如下......
但是当我运行我的项目时,只有else条件正在工作。
没有任何东西传递到数据库
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends Activity {
EditText un,pw,vn;
Button ok,reg;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
un=(EditText)findViewById(R.id.u_name);
pw=(EditText)findViewById(R.id.passwd);
vn=(EditText)findViewById(R.id.vh_number);
ok=(Button)findViewById(R.id.btnlogin);
reg=(Button)findViewById(R.id.btnregister);
ok.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));
postParameters.add(new BasicNameValuePair("vehiclenumber", vn.getText().toString()));
//String valid = "1";
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://192.168.1.23/test_login/check.php", postParameters);
Log.d("sarath","");
String res=response.toString();
// res = res.trim();
res= res.replaceAll("\\s+","");
//error.setText(res);
if(res.equals("1"))
{
Intent i = new Intent(getApplicationContext(),
MainActivity.class);
startActivity(i);
}
else
{
Context context = getApplicationContext();
CharSequence message = "The Username or Password you entered is incorrect.!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, message, duration);
toast.show();
}
} catch (Exception e) {
un.setText(e.toString());
}
}
});
}
}