当我尝试通过用户控制面板网站删除某些角色数据库时,出现了问题。
这是我的功能代码:
function DeleteChar() {
global $pdo;
if($_POST['name'] !== ''&& $_POST['characterid'] !== ''){
$charname = $_POST['name'];
$delchar = $_POST['characterid'];
$query = $pdo->prepare("SELECT * FROM `characters` WHERE `name` = :namechar");
$query->execute(array(
':namechar' => $charname
));
if($_SESSION['adminlvl'] == 5 || $_SESSION['adminlvl'] == 10) {
$query2 = $pdo->prepare("DELETE from `characters` where `characters`.`characterid` = :del_char and `name`= :namechar");
$query2->execute(array(
':del_char' => $delchar,
':namechar' => $charname
));
if($query->rowCount() > 0) {
Logs(2, "Successfully deleted the character from the database");
GetMessage("Congratulation!", "Successfully deleted ". $charname . " ! ", 3);
}
else {
GetMessage("Oh snap!", "Failed to delete" . $charname . " from the database!", 1);
}
}
else {
GetMessage("Oops!", "Unable to delete the character from the database!", 1);
}
}
else {
GetMessage("Oh snap!", "Character name is empty!", 1);
}
echo "<meta http-equiv='refresh' content='2'>";
}
$_SESSION['adminlvl'] == 5 || $_SESSION['adminlvl'] == 10
仅用于特殊的管理员级别,他们可以尝试从数据库中删除字符。
我的表characters
充满了'name' 'characterid' and 'userid'
我尝试了将近两天,但不知道问题出在哪里。
无论如何,我与此类似functions
,并且可以正常工作
function RemoveStaff() {
global $pdo;
if($_POST['forumname'] !== '') {
$forumname = $_POST['forumname'];
if($_SESSION['adminlvl'] == 9 || $_SESSION['adminlvl'] == 10) {
$query = $pdo->prepare("UPDATE `users` SET `adminlvl` = '0' WHERE `user` = :username");
$query->execute(array(
':username' => $forumname
));
if($query->rowCount() > 0) {
Logs(2, "Successfully kicked " . $forumname . " from the staff team");
GetMessage("Congratulation!", "Successfully kicked " . $forumname . " from the staff team!", 3);
}
else {
GetMessage("Oh snap!", "Failed to kick user from the staff team!", 1);
}
}
else {
GetMessage("Oops!", "Unable to remove ".$forumname." from the staff team", 1);
}
}
else {
GetMessage("Oh snap!", "UCP name is empty!", 1);
}
echo "<meta http-equiv='refresh' content='2'>";
}
第二个function RemoveStaff()
正在工作。但是第一个不起作用。我很感激谁能找出问题所在。