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 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程