我已经为 android 登录写了一个简单的 php 脚本,但我不知道为什么它总是返回未找到的用户。我调试了我的 android apk 它在那里很好但是当我检查 php 脚本时它总是返回 false user not found below is my script
// i tried echoing everything possible but no outcome
<?php
include("conn.php");
if(isset($_POST['btn_login'])){
$username = $_POST['username'];
$password = $_POST['password'];
}
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1";
$result = mysqli_query($conn,$sql);
$response = array();
if(mysqli_num_rows($result)>0){
$row = mysqli_fetch_row($result);
$username = $row['username'];
$password = $row['password'];
$code = "login_success";
array_push($response,array("code"=>$code,"username"=>$username,"password"=>$password));
echo json_encode($response);
}
else{
$code = "login_failed";
$message = "User not found... Please try again";
array_push($response, array("code"=>$code,"message"=>$message));
echo json_encode($response);
}
mysqli_close($conn);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" name="btn_login">
</form>
</body>
</html>
最佳答案
你说你使用 sha1 作为密码,在放入 SELECT
之前尝试将 sha1 编码为 $password
关于php登录脚本总是返回错误的用户未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49609675/