繁体   English   中英

管理控制台脚本无法正常运行

[英]Admin panel script not functioning properly

脚本如下...

<?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['gameupdates'] update;如果任务在$_GET['tasklist']$_GET['tasklist'] task。

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

现在,如果有人在$_GET['tab'] = updates单击链接'Delete',则$delete = update 因此,elseif $_GET['tab'] = process的第二个elseif语句将触发,并且确实如此。

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

取而代之的是,更新会一直触发,并且查询失败,您会注意到,查询后,标头重定向到上一个页面,其中包含一个确认操作的会话。 当我单击$_GET['tab'] = tasklist中的'Delete'中的链接时,它将触发一个以进行更新,而应为$_GET['tab'] = tasklist触发一个。

我希望这是有道理的,因为我坚持做下去,我认为所有规则都正确,我看不到自己的错误...

感谢您的耐心配合(以及很多帮助!!!)

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

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

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

elseif ($delete = 'update') {

相反,您应该检查$delete包含值'update':

elseif ($delete == 'update') {

您将需要在多个位置进行此更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM