私のデータベースから値を取得し、それらを変数に代入したいと考えています。これは私のコードです。bind_resultとfetchを使って変数に値を代入する方法は?
$stmt = $this->conn->prepare("SELECT ngno, email, encrypted_password, name, user_type FROM `guide` WHERE email = ?");
$stmt->bind_param("s", $email);
if ($stmt->execute()) {
$stmt->bind_result($ngno, $email, $encrypted_password, $name, $user_type);
$user = $stmt->fetch();
$stmt->close();
if($encrypted_password == $password){
return $user;
}
} else {
return NULL;
}
myテーブルの値を変数$ userに割り当てて、login.phpファイルに戻す必要があります。
$user = $db->getUserByEmailAndPassword($email, $password);
if ($user != false) {
// use is found
$response["error"] = FALSE;
$response["ngno"] = $user["ngno"];
$response["user"]["email"] = $user["email"];
$response["user"]["name"] = $user["name"];
$response["user"]["user_type"] = $user["user_type"];
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!";
echo json_encode($response);
}
私のコードでは、$ user変数に値が割り当てられていないようです。私は間違って何をしていますか?
@RyanAluvihare喜んで私は助けることができました。 *乾杯!:-) –