使用 mysqli 查询失败
Failing query using mysqli
尊敬的 Whosebug 社区,我似乎遇到了问题。我正在为我的 SAMP 服务器制作一个 UCP,但我的一个管理功能文件有问题。
<?php
session_start();
if($_SESSION['admin'] == 0) {
echo '<script>setTimeout("window.location=\'../index.php\'", 0)</script>';
}
include("../includes/connect.php");
$Charname = $_POST['charname'];
$Username = $_POST['username'];
$Faction = (int)$_POST['faction'];
$Rank = (int)$_POST['rank'];
$query = $mysqli->query("UPDATE characters SET Faction='$Faction', FactionRank='$Rank' WHERE Username='$Username' AND Character='$Charname'");
if($query == false) {
echo '<div class="error" id="error">Your request cannot be handled at this time.</div>';
} else {
header("Location: ../changepfac.php");
}
?>
这是我用于表单操作的页面。问题似乎是查询,因为这是我应该得到的输入:
UPDATE characters SET Faction='5', FactionRank='6' WHERE Username='Derek_McFlies' AND Character='Derek_McFlies';
当我在 phpMyAdmin 中执行它时,出现以下错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '='Derek_McFlies'' at line 1
查询的重点是检查用户名和角色名是否与数据库中的相同,然后用玩家的新阵营和阵营等级更新它们。
如果有人能帮我解决这个问题,那就太好了!
此致,
帕维尔
character
是一个 reserved keyword。如果你想用它命名一个列标识符,你 必须 将它包装在刻度中:
UPDATE characters SET Faction='5', FactionRank='6' WHERE Username='Derek_McFlies' AND `Character`='Derek_McFlies';
尊敬的 Whosebug 社区,我似乎遇到了问题。我正在为我的 SAMP 服务器制作一个 UCP,但我的一个管理功能文件有问题。
<?php
session_start();
if($_SESSION['admin'] == 0) {
echo '<script>setTimeout("window.location=\'../index.php\'", 0)</script>';
}
include("../includes/connect.php");
$Charname = $_POST['charname'];
$Username = $_POST['username'];
$Faction = (int)$_POST['faction'];
$Rank = (int)$_POST['rank'];
$query = $mysqli->query("UPDATE characters SET Faction='$Faction', FactionRank='$Rank' WHERE Username='$Username' AND Character='$Charname'");
if($query == false) {
echo '<div class="error" id="error">Your request cannot be handled at this time.</div>';
} else {
header("Location: ../changepfac.php");
}
?>
这是我用于表单操作的页面。问题似乎是查询,因为这是我应该得到的输入:
UPDATE characters SET Faction='5', FactionRank='6' WHERE Username='Derek_McFlies' AND Character='Derek_McFlies';
当我在 phpMyAdmin 中执行它时,出现以下错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '='Derek_McFlies'' at line 1
查询的重点是检查用户名和角色名是否与数据库中的相同,然后用玩家的新阵营和阵营等级更新它们。
如果有人能帮我解决这个问题,那就太好了!
此致, 帕维尔
character
是一个 reserved keyword。如果你想用它命名一个列标识符,你 必须 将它包装在刻度中:
UPDATE characters SET Faction='5', FactionRank='6' WHERE Username='Derek_McFlies' AND `Character`='Derek_McFlies';