在IF语句中使用来自HttpClient的响应时遇到问题。 我用它来验证登录的用户名和密码,这里是登录类
public class loginClass {
public static String verify(EditText username, EditText password){
String UN = username.getText().toString();
String PW = password.getText().toString();
String PWencrypt = Encrypt.md5(PW);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://cstudios.co.uk/cstudiosApps/Login.php?UN="+UN+"&PW="+PWencrypt);
try{
// Execute HTTP Post Request
BasicHttpResponse response = (BasicHttpResponse) httpclient.execute(httppost);
String Val = EntityUtils.toString(response.getEntity());
String[] Value = Val.split(",");
if(Value[1] == "FAIL"){
return "False";
}else{
String UserID = Value[1];
return UserID;
}
} catch (ClientProtocolException e) {
return "Error";
} catch (IOException e) {
return "Error";
}
}
}
以下是PHP文件的代码:
<?php
//Getting Username from APP
$UN = $_GET["UN"];
$UN = mysql_real_escape_string($UN);
$PW = $_GET["PW"];
// Create Connection
$con=mysqli_connect($URL,$username,$password,$Database);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Login Query
$GetPW = mysqli_query($con,"SELECT * FROM users WHERE Username='$UN'");
while($row = mysqli_fetch_array($GetPW))
{
$PWtest=$row['Password'];
$USERid=$row['UserID'];
}
if($PW==$PWtest)
{
echo "," . $USERid . ",";//for use of APP
}else{
echo ',FAIL,';
}
//Close Connection
mysqli_close($con);
?>
我设置了上面的Sql变量我只是不想粘贴它,对此的任何帮助都会很棒,使用时会出现问题
if(Value[1] == "FAIL")
因为它永远不会返回false ... 提前感谢您的帮助。
答案 0 :(得分:1)
使用.equals()方法比较java中的字符串。