我在此有这一法典。
My java守则:
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
$public void onClick(View v) {
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", txtUsername.getText().toString()));
postParameters.add(new BasicNameValuePair("password", txtPassword.getText().toString()));
//String valid = "1";
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://www.sampleweb.com/imba.php", postParameters);
String res=response.toString();
// res = res.trim();
res= res.replaceAll("\s+","");
//error.setText(res);
if(res.equals("1")){
txtError.setText("Correct Username or Password");
//Intent i = new Intent(CDroidMonitoringActivity.this, MenuClass.class);
//startActivity(i);
}
else {
txtError.setText("Sorry!! Incorrect Username or Password");
}
} catch (Exception e) {
txtUsername.setText(e.toString());
}
}
});
}
My php script code:
<?php
$un=$_POST[ username ];
$pw=$_POST[ password ];
$user = ‘bduser’;
$pswd = ‘dbpwd’;
$db = ‘phplogin’;
$conn = mysql_connect("localhost","root","");
mysql_select_db($db, $conn);
$query = mysql_query("SELECT * FROM user WHERE username = $un AND password = $pw ");
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());
if(mysql_num_rows($result) == 1)
echo 1; // for correct login response
else
echo 0; // for incorrect login response
?>
我对这一法典有问题。 在我和roid的法典中,我试图将第2类平等的内容改写。 它总是说正确的密码,但如果我不会改变的话,它就说的是错误的密码。 我不知道我的java法典或我的营地法典中有一些错误。 确实需要帮助。