gpt4 book ai didi

php - 将 MySQL 查询结果传递到 PHP session 登录

转载 作者:行者123 更新时间:2023-11-29 19:30:07 24 4
gpt4 key购买 nike

我正在尝试修复 friend 的旧项目的登录系​​统,但我似乎无法让它接受合法的登录,而不是从数据库传递用户名和 ID,它只是即使它可以从数据库获取正确的用户名和 ID,也会引发错误。知道是否是这部分代码导致了错误以及解决方案是什么?

MySQL 查询和 PHP session

<?php
$row = mysqli_fetch_assoc(mysqli_query($con,'SELECT id,usr FROM tz_members WHERE usr="{.$_POST[username]}" AND pass="{.$_POST[password]}"'));
if($row['usr'])
{
$_SESSION['usr'] = $row['usr'];
$_SESSION['id'] = $row['id'];
$_SESSION['rememberMe'] = $_POST['rememberMe'];
}
else {
//(display error message)
}
?>

登录表单

<form>
<label class="grey" for="username">Username:</label>
<input class="field" type="text" name="username" id="username" value="" size="23" />
<label class="grey" for="password">Password:</label>
<input class="field" type="password" name="password" id="password" size="23" />
<label><input name="rememberMe" id="rememberMe" type="checkbox" checked="checked" value="1" /> &nbsp;Remember me</label>
<div class="clear">
</div>
<input type="submit" name="submit" value="Login" class="bt_login" />
</form>

完整代码

http://pastebin.com/kj6i9Y8h

最佳答案

我希望这有帮助:)

$row = mysqli_fetch_assoc(mysqli_query($con,'SELECT "id", "usr" FROM "tz_members" WHERE usr="'.$_POST['username'].'" AND pass="'.$_POST['password'].'"'));

关于php - 将 MySQL 查询结果传递到 PHP session 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41843072/

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