我一直在尝试让一个按钮在验证用户输入正确的用户名/密码后转到一个页面,我已经部分完成了,问题是当我点击按钮时它没有验证用户名/密码,它只是转到位置。 我正在使用 HTML、CSS、javascript 和 PHP。 这是代码。
<?php
// include database and object files
include_once '../config/database.php';
include_once '../objects/user.php';
// get database connection
$database = new Database();
$db = $database->getConnection();
// prepare user object
$user = new User($db);
// set ID property of user to be edited
$user->username = isset($_GET['username']) ? $_GET['username'] : die();
$user->password = base64_encode(isset($_GET['password']) ? $_GET['password'] : die());
// read the details of user to be edited
$stmt = $user->login();
header('Location: ../../../../Home/index.html');
if($stmt->rowCount() > 0){
// get retrieved row
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// create array
$user_arr=array(
"status" => true,
"message" => "Successfully Login!",
"id" => $row['id'],
"username" => $row['username']
);
}
else{
$user_arr=array(
"status" => false,
"message" => "Invalid Username or Password!",
);
}
// make it json format
print_r(json_encode($user_arr));
?>
这是一个视频... https://youtu.be/Li__rDSdEbs
最佳答案
问题是您在获取用户数据之前定位到其他页面,
if($stmt->rowCount() > 0){
// get retrieved row
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// create array
$user_arr=array(
"status" => true,
"message" => "Successfully Login!",
"id" => $row['id'],
"username" => $row['username']
);
header('Location: ../../../../Home/index.html');}
关于javascript - 在PHP中验证数据库中的用户名和密码后,如何使按钮转到特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59018814/