简体   繁体   English

如何查看数据库中的数据?

[英]how to check the data in the database?

Tell me how to configure authorization.告诉我如何配置授权。 Php I know basically, since I don't work with it, but I need to implement this task. Php 我基本上知道,因为我不使用它,但我需要实现这个任务。 I would like that when clicking on the button authorization passes and goes to another page.我希望当点击按钮授权通过并转到另一个页面时。 I do not fully understand how to check the data in the database and compare it with user data and, if there is a coincidence, re-direct to another page.我不完全了解如何检查数据库中的数据并将其与用户数据进行比较,如果有巧合,请重定向到另一个页面。 Did you go the right way?您的 go 方法是否正确? How can I solve my problem?我该如何解决我的问题?

authdb.php authdb.php

<?php
$dbname = "dictdb";
$username = "root";
$userpass = "";
$charset = "utf8";
$options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];

$userdata = [
    "logVal" => trim($_POST["logVal"]),
    "passVal" => trim($_POST["passVal"])
];

$db = new PDO("mysql:host=$dbhost;dbname = $dbname;charset=$charset", $username, $userpass, $options);
if (!empty(trim($_POST["logVal"])) && !empty(trim($_POST["passVal"]))) {
    $query = "SELECT * FROM  `dictdb`.`user` WHERE `login` = :logVal AND `password` = :passVal";
    $user_data = $query-fetchAll();

if ($user_data[password] == :passVal) {
echo "ok";
};

?>

auth.php auth.php

$(document).ready(function () {
    $("button.btn-auth").on("click", function () {
        $.ajax({
            url: '/src/php/auth.php',
            type: "POST",
        });
    });
});

First things first, you are doing a table search that will return only 1 row, so change your fetchAll to fetch -首先,您正在执行仅返回 1 行的表搜索,因此将 fetchAll 更改为 fetch -

// change this - $user_data = $query-fetchAll(); to
$user_data = $query-fetch(PDO::FETCH_ASSOC);
//This part is also incorrect - if ($user_data[password] == :passVal) as there is no $user_data[password] and will return an error... Change to -
if ($user_data[passVall] == :passVal)

You are then posting to the wrong page, your PHP login data will never run - //url: '/src/php/auth.php' should be - url: '/src/php/authdb.php',然后您发布到错误的页面,您的 PHP 登录数据将永远不会运行 - //url: '/src/php/auth.php' 应该是 - url: '/src/php/authdb.php',

In your authdb.php page, return the $user_data to your auth.php page if login was successful -在您的 authdb.php 页面中,如果登录成功,则将 $user_data 返回到您的 auth.php 页面 -

 if ($user_data[password] == :passVal) {
  return $user_data;
  //direct user back to your auth page -
  include( '../auth.php' ); //check correct path...
 };

Now do with the returned data as you wish, I would personally have loaded the returned data in my authdb.php page to a session though.现在按照您的意愿处理返回的数据,我个人会将我的 authdb.php 页面中的返回数据加载到 session 中。

Your post part is incorrect, you can do something to this effect -您的帖子部分不正确,您可以为此做一些事情-

 $.post("../authdb.php", {
    logVal: logVal,
    passVal: passVal
 },
    function (data) {
     if (data == '0') {
        alert("Incorrect or Invalid Password entered.");

        return false;
     } else {
        alert("Sign In successful.");
 }

In your authdb.php file, after checking the passwords etc match -在您的 authdb.php 文件中,检查密码等匹配后 -

if ($user_data[passVal] == :passVal) {
 echo count($user_data); //Will return 0 if failed, 1 if success
    die;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查两个类似的数据库调用是否在php中返回相同的数据 - How to check if two similar calls to database return same the data in php 如何使用ajax方法交叉检查数据库中是否存在数据? - How to cross check if data is present in the database using ajax method? 如果数据是通过循环从数据库接收的,如何检查复选框是否被选中 - How to check a checkbox is checked or not if data is receiving from database via a loop 如何检查从 mongo 数据库接收到的数据是否为空? - How to check if data received from mongo database is empty? 如何检查选中的复选框,并使用Angular将数据保存到数据库中 - How to check which checkbox is checked and save the data into database using Angular 如何查看collectionFS数据库? - How to check collectionFS database? 如何通过从 ASP.NET MVC 中的数据库检索数据来选中/取消选中复选框列表 - How to Check/Unchecked the check box list by retrieving the data from database in ASP.NET MVC 如果从数据库获取数据后选中一个复选框,如何禁用其他复选框 - How to disabled other check-boxes if one check-box is checked after fetching data from database 如何检查数据库,并因此检查单选按钮? - How to check database and, as a result, check a radio button? 如何检查数据库是否需要身份验证 - how to check if database needs auth or not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM