Javascript 无法获取登录页面的PHP web api错误数据
上面的代码是登录页面的登录web api,但当我运行此页面时,出现错误{“error”:true,“error_msg”:“缺少必需的参数登录ID或密码!”},但我的密码和参数在错误的地方是正确的 下面的代码是db function.phpJavascript 无法获取登录页面的PHP web api错误数据,javascript,php,mysql,json,api,Javascript,Php,Mysql,Json,Api,上面的代码是登录页面的登录web api,但当我运行此页面时,出现错误{“error”:true,“error_msg”:“缺少必需的参数登录ID或密码!”},但我的密码和参数在错误的地方是正确的 下面的代码是db function.php <?php require_once 'include/DB_Functions.php'; $db = new DB_Functions(); // json response array $response = array("error" =&
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['loginid']) && isset($_POST['password']))
{
// receiving the post params
$loginid = $_POST['loginid'];
$password = $_POST['password'];
// get the user by loginid and password
$user = $db->getUserByEmailAndPassword($loginid, $password);
if ($user != false) {
// user is found
$response["error"] = FALSE;
$response["No"] = $user["No"];
$response["user"]["username"] = $user["username"];
$response["user"]["loginid"] = $user["loginid"];
$response["user"]["password"] = $user["password"];
$response["user"]["role"] = $user["role"];
$response["user"]["designation"] = $user["designation"];
$response["user"]["status"] = $user["status"];
//$response["user"]["designation"] = $user["designation"];
header('Content-type: application/json');
echo json_encode($response);
} else {
// user is not found with the credentials
$response["error"] = TRUE;
$response["error_msg"] = "Login credentials are wrong. Please try again!";
header('Content-type: application/json');
echo json_encode($response);
}
} else {
// required post params is missing
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters login ID or password is missing!";
header('Content-type: application/json');
echo json_encode($response);
}
?>
如果(isset($\u POST['loginid'])和(isset($\u POST['password']))的计算结果为false,则我错了或任何错误或任何想法。因此,对php页面的调用中缺少了两个字段中的一个。。以下是无处可去的额外值的线索
NOW()
和。。$No、$status、$email、$role、$loginid、$username、$designation、$password
这些都存储在您的公共功能中,它们在哪里?我只看到loginid和password。@Sloachr这不是唯一返回响应的情况,显示您在getUserByEmailAndPassword
中重写了原始的$password
。如果($password==$password),那么是什么?
<?php
class DB_Functions {
private $conn;
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$db = new Db_Connect();
$this->conn = $db->connect();
}
// destructor
function __destruct() {
}
/**
* Storing new user
* returns user details
*/
public function storeUser($loginid, $password) {
$stmt = $this->conn->prepare("INSERT INTO cz(No, status, email, role, loginid, username, designation, password ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, NOW())");
$stmt->bind_param("ssssssss", $No, $status, $email, $role, $loginid, $username, $designation, $password );
$result = $stmt->execute();
$stmt->close();
if ($result) {
$stmt = $this->conn->prepare("SELECT * FROM cz WHERE loginid = ?");
$stmt->bind_param("s", $loginid);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
return $user;
} else {
return false;
}
}
/**
* Get user by login id and password
*/
public function getUserByEmailAndPassword($loginid, $password) {
$stmt = $this->conn->prepare("SELECT * FROM cz WHERE loginid = ?");
$stmt->bind_param("s", $loginid);
if ($stmt->execute()) {
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
// verifying user password
$password = $user['password'];
// check for password equality
if ($password == $password) {
// user authentication details are correct
return $user;
}
} else {
return NULL;
}
}
/**
* Check user is existed or not
*/
public function isUserExisted($loginid) {
$stmt = $this->conn->prepare("SELECT loginid from cz WHERE loginid = ?");
$stmt->bind_param("s", $loginid);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
// user existed
$stmt->close();
return true;
} else {
// user not existed
$stmt->close();
return false;
}
}
}
?>