![](/img/trans.png)
[英]How do you make a submit button redirect to another page after the user has inputted the correct username and password?
[英]How do you make a button go to a specific page after validating the Username and Password from the Database in PHP
我一直在尝试让按钮在验证用户输入正确的用户名/密码后转到页面,我已经部分完成了,问题是当我单击按钮时它不会验证用户名/password,它只会转到位置。 我正在使用 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');}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.