gpt4 book ai didi

php - 管理面板脚本无法正常运行

转载 作者:行者123 更新时间:2023-11-29 14:44:41 26 4
gpt4 key购买 nike

脚本如下...

<?php

// ########## GAME UPDATE FORM ##########

if (isset($_GET['tab']) && $_GET['tab'] === 'gameupdates') {

$delete = 'update';

if (isset($_SESSION['success'])) {

echo $_SESSION['success'];
unset($_SESSION['success']);
}

echo '<p>To make a new game update fill out the form below along with the type of update it corresponds to.</p><p>If you have completed a task make sure to remove it from the <a href="/adminpanel?tab=tasklist">task list</a>.</p><form action="/adminpanel?tab=process" method="post">
<fieldset>
<input type="hidden" name="newupdate" />
<textarea name="message"></textarea>
<select name="type">
<option value="Community">Community</option>
<option value="Security">Security</option>
<option value="Gameplay">Gameplay</option>
<option value="Account">Account</option>
<option value="Miscellaneous">Misc.</option>
</select>
<input id="submit" type="submit" value="Insert Update" />
</fieldset>
</form><p>The last six updates were as follows from newest to oldest:</p><p>(To delete an entry hover over the update and press delete)</p>';

$q = $dbc -> prepare ("SELECT * FROM updates ORDER BY date_time DESC LIMIT 0, 6");
$q -> execute();

while ($update = $q -> fetch(PDO::FETCH_ASSOC)) {

echo '<div id="displaybox"><div><strong>' . $update['date_time'] . '</strong><span>' . $update['type'] . '</span></div><p>' . $update['message'] . '</p><a href="/adminpanel?tab=process&update=' . $update['date_time'] . '">Delete</a></div>';
}
}

// ########## TO DO LIST ##########

elseif (isset($_GET['tab']) && $_GET['tab'] === 'tasklist') {

$delete = 'task';

if (isset($_SESSION['success'])) {

echo $_SESSION['success'];
unset($_SESSION['success']);
}

echo '<p>This is the to do list anything that needs to be done whether it be urgent or not put it here.</p><p>Remember once the task has been completed remember to add it to the <a href="/adminpanel?tab=gameupdates">game updates</a>.</p><p>Below (if any) are the current tasks that need doing, to add a new task complete the form at the bottom of this page.</p>';

$q = $dbc -> prepare ("SELECT * FROM tasks ORDER BY date_time");
$q -> execute();

while ($task = $q -> fetch(PDO::FETCH_ASSOC)) {

echo '<div id="displaybox"><div><strong>' . $task['date_time'] . '</strong><span>' . $task['type'] . '</span></div><p>' . $task['message'] . '</p><a href="/adminpanel?tab=process&task=' . $task['date_time'] . '">Delete</a></div>';
}

echo '<p>To add a task complete the form below, along with which type of update it is.</p><p>To delete a task once it has been completed hover over the task and press delete.</p><form action="/adminpanel?tab=process" method="post">
<fieldset>
<input type="hidden" name="newtask" />
<textarea name="message"></textarea>
<select name="type">
<option value="Community">Community</option>
<option value="Security">Security</option>
<option value="Gameplay">Gameplay</option>
<option value="Account">Account</option>
<option value="Miscellaneous">Misc.</option>
</select>
<input id="submit" type="submit" value="Insert New Task" />
</fieldset>
</form>';
}

// ########## PROCESS ADMIN CHANGES ##########

elseif (isset($_GET['tab']) && $_GET['tab'] === 'process') {

// ########## GAME UPDATE SUCCESS ##########

if (isset($_POST['newupdate'])) {

if ($_POST['message'] === '') {
header('Location:/adminpanel?tab=gameupdates');
exit();
}

$q = $dbc -> prepare("INSERT INTO updates (message, type, date_time) VALUES (?, ?, ?)");
$q -> execute(array($_POST['message'], $_POST['type'], date("y/m/d : H:i:s", time())));
$_SESSION['success'] = '<p><strong>Successfully added a new game update.</strong></p>';
header('Location:/adminpanel?tab=gameupdates');
exit();
}

// ######### TO DO LIST SUCCESS ##########

elseif (isset($_POST['newtask'])) {

if ($_POST['message'] === '') {
header('Location:/adminpanel?tab=tasklist');
exit();
}

$q = $dbc -> prepare("INSERT INTO tasks (message, type, date_time) VALUES (?, ?, ?)");
$q -> execute(array($_POST['message'], $_POST['type'], date("y/m/d : H:i:s", time())));
$_SESSION['success'] = '<p><strong>Successfully added a new task.</strong></p>';
header('Location:/adminpanel?tab=tasklist');
exit();
}

// ########## GAME UPDATE DELETE ##########

elseif ($delete = 'update') {

$q = $dbc -> prepare("DELETE FROM updates WHERE date_time = ?");
$q -> execute(array($_GET['update']));
$_SESSION['success'] = '<p><strong>Successfully deleted the selected update.</strong></p>';
header('Location:/adminpanel?tab=gameupdates');
exit();
}

// ########## TO DO LIST DELETE ##########

elseif ($delete = 'task') {

$q = $dbc -> prepare("DELETE FROM tasks WHERE date_time = ?");
$q -> execute(array($_GET['task']));
$_SESSION['success'] = '<p><strong>Successfully deleted the selected task.</strong></p>';
header('Location:/adminpanel?tab=tasklist');
exit();
}

else {

header('Location:/adminpanel');
exit();
}
}

// ########## ADMIN CONTROL PANEL ##########

else {
echo '<p>This is the admin panel. Click on an option below to begin.</p><p><a href="/adminpanel?tab=gameupdates">Add/Remove A Game Update</a></p><p><a href="/adminpanel?tab=tasklist">Add/Remove A Task From List</a></p>';
}
?>

我知道这是一个很长的脚本,但您需要查看全部内容才能理解它,除了一个小错误之外,该脚本运行良好。

您会注意到第一个 if 语句有一个变量

$delete = 'update';

这意味着如果$_GET['tab'] = gameupdates$delete = 'update'

第二个 elseif 不同...

if $_GET['tab'] = tasklist, $delete = 'task'

在前两个 if 和 else if 语句中,有 while 循环,其中包含类似的链接

<a href="adminpanel?tab=process&update OR task=' . some variable . '">Delete</a>

现在,如果链接位于 $_GET['gameupdates'] 中,则链接为更新;如果链接位于 $_GET['tasklist'] 中,则链接为任务。

在第三个 elseif 语句中,其中 $_GET['tab'] = process,前两个语句用于表单提交,但最后两个 elseif 语句是我解释的链接的内容对于。

现在,如果有人在 $_GET['tab'] = update 中点击“删除”链接,$delete = update。因此 elseif $_GET['tab'] = process 中的第二个 elseif 语句被触发,并且确实如此。

问题是,如果有人在 $_GET['tab'] = tasklist 中点击链接,则 $delete = task。因此,elseif 语句 $_GET['tab'] = process 中的第三个 elseif 语句应作为 $delete = task 触发。

相反,更新始终会触发,并且查询失败,您会注意到在查询之后, header 重定向到上一页,其中包含包含操作确认的 session 。当我单击 $_GET['tab'] = tasklist 中“删除”中的链接时,它会触发用于更新的链接,而它应该触发 $_GET['tab 的链接'] = 任务列表

我希望这是有道理的,我被困在该怎么做,我认为我所有的规则都是正确的,我看不到我的错误......

感谢您的耐心(而且非常耐心!!!)

最佳答案

您的代码引用了 $_SESSION 变量,但从未启动 session (session_start())。您需要在脚本顶部使用 session_start() 来访问 session 数据。

此外,“=”是赋值运算符。您需要一个相等运算符('==')。

在下面的行中,将“update”的值分配给 $delete

elseif ($delete = 'update') {

相反,您应该检查 $delete 是否包含值“update”:

elseif ($delete == 'update') {

您需要在多个地方进行此更改。

关于php - 管理面板脚本无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7234358/

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