Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 管理面板脚本无法正常运行_Php_Mysql_Variables_Get_Pdo - Fatal编程技术网

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

Php 管理面板脚本无法正常运行,php,mysql,variables,get,pdo,Php,Mysql,Variables,Get,Pdo,剧本如下 <?php // ########## GAME UPDATE FORM ########## if (isset($_GET['tab']) && $_GET['tab'] === 'gameupdates') { $delete = 'update'; if (isset($_SESSION['success'])) { echo $_SESSION['success']; unset($_SESSION['success']); }

剧本如下

<?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>';
}
?>
这意味着如果
$\u GET['tab']=gameupdates
$delete='update'

第二个是不同的

if $_GET['tab'] = tasklist, $delete = 'task'
在前两个if和elseif语句中,有while循环,其中包含类似的链接

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

现在,如果链接位于
$\u GET['gameupdates']
中,则该链接为update;如果链接位于
$\u GET['tasklist']
中,则该链接为task

在第三个elseif语句中,其中
$\u GET['tab']=process
,前两个语句用于表单提交,但最后两个elseif语句是我解释的链接的目的

现在,如果有人在
$\u GET['tab']=updates
$Delete=update
中单击“Delete”链接。因此,elseif
$\u GET['tab']=process
中的第二条elseif语句启动,它确实启动了

问题是,如果有人在
$\u GET['tab']=tasklist
中单击链接,则
$delete=task
。因此,elseif语句
$\u GET['tab']=process
中的第三条elseif语句应该作为
$delete=task
启动

相反,update one会一直启动,并且查询会失败,您会注意到,在查询之后,标头会重定向到上一页,其中包含一个包含操作确认的会话。当我在
$\u GET['tab']=tasklist
中单击“Delete”中的链接时,它会触发一个用于更新的链接,而此时它应该触发一个用于
$\u GET['tab']=tasklist
的链接

我希望这是有意义的我被困在做什么,我所有的规则我认为是正确的,我看不到我的错误


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

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

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

在下一行中,您将“更新”的值分配给
$delete

elseif ($delete = 'update') {
相反,您应该检查
$delete
是否包含值“update”:

elseif ($delete == 'update') {

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

我尝试了您的答案,但没有成功,然后我决定使用sessions,以及您的答案,它成功了,请您解释一下,以供将来参考。
elseif ($delete == 'update') {