我一直在关注一个android教程,它涉及到将android应用程序连接到您的数据库。 Android的位从登录部分我认为这是由在PHP script.Here的问题引起的工作就好了与众不同的是PHP代码:PHP isset is not working
<?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的代码如下
@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();
}
}
当使用isset时,成功位不会被回显,而是直接跳转到登录成功。我需要这一点回声,以便我的Android应用程序能够正确登录。
if(isset($_POST['mobile'])
{
if(($_POST['mobile'] == "android"))
{
echo "success";
exit;
}
}
else
{ echo "mobile parameter is not set";
强制您有SQL注入漏洞的评论。另外,它看起来像你以纯文本存储密码。本教程应该感到羞耻。可能不是你的直接问题的来源,但这里有一些必要的阅读:[我怎样才能防止SQL注入PHP?](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-注入在PHP中)和[安全哈希和盐的PHP密码](http://stackoverflow.com/questions/401656/secure-hash-and-salt-for-php-passwords) –
把print_r($ _ POST) ;在<?php之后回显所有$ _POST变量并确保$ _POST ['mobile']实际上存在 – emed