gpt4 book ai didi

php - 检索数据时出现 SQL 错误

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

无论我更改什么,我都会继续运行此代码并得到相同的错误。

require('common.php');
$charname = $_SESSION['user']['username'];
$query = "SELECT group, guild, username, class, level
FROM DD_users
WHERE username = '".$charname."'";
try
{
// These two statements run the query against your database table.
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}

// Finally, we can retrieve all of the found rows into an array using fetchAll
$rows = $stmt->fetchAll();

//print_r($rows);
$group = $rows['0']['adminaccess'];
$guild = $rows['0']['guild'];
$username = $rows['0']['username'];
$class = $rows['0']['class'];
$level = $rows['0']['level'];

它返回这个错误
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“group, guild, username, class, level FROM DD_users”附近使用的正确语法显然我需要更多文本才能编辑它...

最佳答案

您忘记了 ' 字符:

$query = "SELECT group, guild, username, class, level 
FROM DD_users
WHERE username = '".$charname."'";

关于php - 检索数据时出现 SQL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14006376/

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