dopr25398 2018-03-01 08:27
浏览 30
已采纳

为什么我的删除功能不起作用? [重复]

This question already has an answer here:

I followed a tutorial on Youtube about how to make a CMS system: http://y2u.be/QNxU3Qa6QZs

And i'm stuck at making the delete function, it just refreshes the page without actually deleting something. Can someone help me with this problem?

This is the code i have for the delete page:

<?php 

session_start();

include_once('../includes/connection.php');
include_once('../includes/article.php');

$article = new Article;

if (isset($_SESSION['logged_in'])) {
    if(isset($_GET['id'])) {

        $id = $GET['id'];

        $query = $pdo->prepare('DELETE FROM articles WHERE article_id = ?');
        $query->bindValue(1, $id);
        $query->execute();

        header('Location: delete.php');
    }

$articles = $article->fetch_all();

 ?>
<html>

<head>
    <title> Blog </title>
    <link rel="stylesheet" href="../assets/style.css" />
</head>

<body>
    <div class="container">
        <a href="index.php" id="logo">CMS</a>
        <br><br>

        <h4>Select an Article to delete </h4>

        <form action="delete.php" method="get">

            <select onchange="this.form.submit();" name="id">

                    <?php foreach ($articles as $article) { ?>
                    <option value="<?php echo $article['article_id']; ?>"> 
                    <?php echo $article['article_title'];   ?>

                </option>
                    <?php } ?>

                </select>
        </form>


    </div>
</body>

</html>

<?php
} else {
header('Location: index.php'); 
}

?>

If you have any questions about the code, i'll answer them.

I hope you'll help me find a solution for this problem.

  • Daniel
</div>
  • 写回答

1条回答 默认 最新

  • dongzheng7165 2018-03-01 08:30
    关注

    You have a typo.

    Change

    $id = $GET['id'];
    

    To

    $id = $_GET['id']; #$_GET is the global array not $GET
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题