亲爱的stackoverflow社区,我似乎遇到了一个问题。我正在为我的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
查询的目的是检查用户名和角色名称是否与数据库中的名称相同,然后使用玩家的新派系和派系等级更新它们。
如果有人可以帮我解决这个问题,那就太好了!
最诚挚的问候, 帕维尔
答案 0 :(得分:2)
character
是reserved keyword。如果你想用它命名一个列标识符,你必须将它包装在刻度线中:
UPDATE characters SET Faction='5', FactionRank='6' WHERE Username='Derek_McFlies' AND `Character`='Derek_McFlies';