gpt4 book ai didi

php - 使用 php 从数据库中获取用户名和密码

转载 作者:行者123 更新时间:2023-11-29 23:05:19 25 4
gpt4 key购买 nike

我正在尝试使用我的数据库检查用户名和密码。但是,每次我尝试使用密码“12341”登录“admin”帐户时,它都不会给我想要的结果。

login.php

<div align="center" position="fixed" >  
<form action="login_process.php" method="post">
<input name="username" type="text" value="" size="9"><br>
<input name="pass" type="password" value="" size="9"><br>
<input type="submit" value="Log in">
</form>
</div>

login_process.php

require_once('db_conn.php');



if (!isset($_POST['username']) || !isset($_POST['pass'])) {
echo 'U moet een gebruikersnaam en wachtwoord invoeren!';
exit;
}

$sql = "SELECT `username`,`password` \n"
. "FROM `tryusers` \n"
. "WHERE `username` = \'Admin\'\n"
. "AND `password` = \'12341\'";
$sql = "SELECT `username`,`password` FROM `tryusers` WHERE `username` = " . $_POST['username'] . " AND password = " . $_POST['pass'] . "";
$results = $conn->query($sql);
var_dump('postuser',$_POST['username'],'<br>');
var_dump('postpass',$_POST['pass'],'<br>');
if(!$results){
echo 'no results';
} else {
echo $results;
}

db_conn.php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "trybase";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

感谢任何帮助。

问候,扫描仪

最佳答案

您必须将变量括起来:

$sql = "SELECT `username`,`password` FROM `tryusers` WHERE `username` = '" . $_POST['username'] . "' AND password = '" . $_POST['pass'] . "'";

或者更好地使用准备好的语句。

关于php - 使用 php 从数据库中获取用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28318572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com