I have been following an android tutorial and it involves linking up the android app to your database. The android bit is working just fine apart from the login part which i think is being caused by a problem in the PHP script.Here is the PHP code:
<?PHP
include_once("conn.php");
if (isset($_POST['txtUsername']) && isset($_POST['txtPassword']))
{
$username = $_POST['txtUsername'];
$password = $_POST['txtPassword'];
$query = "SELECT username, password FROM tbl_client " .
" WHERE username = '$username' AND password = '$password'";
$result = mysqli_query($conn, $query);
if ($result->num_rows > 0)
{
if (isset($_POST['mobile']) && $_POST['mobile'] == "android")
{
echo "success";
exit;
}
echo "login successful";
} //header("location: index.php"); //replace login.php with your url
else
{
echo "Login Failed <br/>";
}
}
Android code is below
@Override
public void processFinish(String result) {
if (result.equals("success")){
Intent intent=new Intent(this,Homepage.class);
startActivity(intent);
}
else
{
Toast.makeText(Login.this,"Login Unsuccessful", Toast.LENGTH_SHORT).show();
}
}
the success bit is never echoed when using the isset, instead it jumps straight to login successful. I need that bit to echo in order for my android app to be able to log in correctly.