gpt4 book ai didi

PHP - 第 60 行出现意外的 Else

转载 作者:行者123 更新时间:2023-11-29 15:53:35 26 4
gpt4 key购买 nike

我正在尝试为我的游戏设置面板。

我已经尝试修复它

<?php
$referer = isset($_SERVER['HTTP_REFERER']) ? _SERVER['HTTP_REFERER'] : 'undefined';
$agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'undefined';

$address = 'undefined';

if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$address = $_SERVER['HTTP_CLIENT_IP'];
} else {
$address = $_SERVER['REMOTE_ADDR'];
}
}

if ($address === '47.39.46.24') {


$host = "localhost";
$dbusername = "asta";
$dbpassword = "***";
$dbname = "asta";
// Create connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
} else {

$roleid = filter_input(INPUT_POST, 'roleid');
$rolename = filter_input(INPUT_POST, 'rolename');
$rolepermission = filter_input(INPUT_POST, 'rolepermission');
$rolecolor = filter_input(INPUT_POST, 'rolecolor');
if (!empty($roleid)) {
if (!empty($rolename)) {
if (!empty($rolepermission)) {
if (!empty($rolecolor)) {
$sql = "SELECT `id` FROM `roles` WHERE `id`='$roleid'";
$result = $conn->query($sql);
if ($result->num_rows >= 1) {
echo "The role with id '$roleid' is already in the database.";
} else {
$sql = "INSERT INTO roles (id, name, permissions, color) values ('$roleid','$rolename','$rolepermission','$rolecolor')";
if ($conn->query($sql)) {
echo "The role '$rolename' has been created!!";
} else {
echo "Error: " . $sql . "" . $conn->error;
}
$conn->close();
}} }
} else {
echo "ROLEID should not be empty";
die();
}
} else {
echo "ROLENAME should not be empty";
die();
}
else {
echo "ROLEPERMISSION should not be empty";
die();
}

else {
echo "ROLECOLOR should not be empty";
die();
}

}

}
?>

我希望它能够处理该请求..

有人可以帮忙吗?我是编码新手,到目前为止你们都给了我很大的帮助。

再次..感谢男孩女孩们所做的一切

我知道该代码容易受到 SQL 注入(inject)攻击。在发布之前我会担心这一点。

最佳答案

由于在 Else 之前关闭了 $rolepermission block (第 51 行),您实际上拥有了一个 IF...ELSE...ELSE 语句。正确缩进代码应该有助于通过使流程更清晰来捕获这些内容。

每个 Else 似乎也乱了套。检查下面的代码,看看它是否按您的预期运行:

<?php
$referer = isset($_SERVER['HTTP_REFERER']) ? _SERVER['HTTP_REFERER'] : 'undefined';
$agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'undefined';

$address = 'undefined';

if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$address = $_SERVER['HTTP_CLIENT_IP'];
} else {
$address = $_SERVER['REMOTE_ADDR'];
}
}

if ($address === '47.39.46.24') {


$host = "localhost";
$dbusername = "asta";
$dbpassword = "***";
$dbname = "asta";
// Create connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);

if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
} else {

$roleid = filter_input(INPUT_POST, 'roleid');
$rolename = filter_input(INPUT_POST, 'rolename');
$rolepermission = filter_input(INPUT_POST, 'rolepermission');
$rolecolor = filter_input(INPUT_POST, 'rolecolor');

if (!empty($roleid)) {
if (!empty($rolename)) {
if (!empty($rolepermission)) {
if (!empty($rolecolor)) {
$sql = "SELECT `id` FROM `roles` WHERE `id`='$roleid'";
$result = $conn->query($sql);

if ($result->num_rows >= 1) {
echo "The role with id '$roleid' is already in the database.";
} else {
$sql = "INSERT INTO roles (id, name, permissions, color) values ('$roleid','$rolename','$rolepermission','$rolecolor')";

if ($conn->query($sql)) {
echo "The role '$rolename' has been created!!";
} else {
echo "Error: " . $sql . "" . $conn->error;
}

$conn->close();
}
}
else {
echo "ROLECOLOR should not be empty";
die();
}
}
else {
echo "ROLEPERMISSION should not be empty";
die();
}
}
else {
echo "ROLENAME should not be empty";
die();
}
}
else {
echo "ROLEID should not be empty";
die();
}
}

}
?>

关于PHP - 第 60 行出现意外的 Else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56624758/

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