I am having a problem when using a response from a HttpClient in an IF statement. I am using it to verify username and password for a login, here is the login class
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";
}
}
}
Here is the code for the PHP file:
<?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);
?>
I set the Sql Variables above I just didn't want to paste that, any help on this will be great, the issue comes when using
if(Value[1] == "FAIL")
as it never returns false... thanks in advance for your help.
String'sequalsmethod to compare string contents, not the==operator.