PHP/MySQL删除记录不删除

PHP/MySQL Delete Record doesn't Delete

这让我发疯!我有一个名为课程列表的网页,我正在使用 PHP 创建一个 HTML table 列表存储在 MySQL 数据库中的课程(使用 Wampserver)

<?php

require "dbconn.php";

$query = "SELECT coursecode, coursename FROM course";

$results = $connect->query($query);

$numrow = $results->num_rows;
?>

<html>
  <head></head>
    <body>
      <table border="1">

        <?php
        $count = 0;
        while ($count < $numrow)
            {
                $row = $results->fetch_assoc();
                extract($row);

                echo "<tr>";

                echo "<td>";
                echo "<a href='updatecourseform.php?coursecode=".$coursecode."'>".$coursecode."</a>";

                echo "<td>";
                echo $row['coursename'];
                echo "</td>";

                echo "<td>";
                echo "<a href='deletecourse.php?coursecode=".$coursecode."'>Delete</a>";
                echo "</td>";

                echo "</tr>";

                $count = $count + 1;
            }
        ?>

        </table>
        <br />
        The number of courses found was: <?php echo $numrow; ?>
        <br /><br />
        Click <a href="addcourse.html">here</a> if you want to add a Course
    </body>
</html>

这会打印出一个漂亮的 HTML table,其中包含正确的所有数据,右侧的一行带有 Delete 一词,这是一个超链接,应该允许我删除一个课程。但是当我点击删除时,它并没有删除!这是我的 deletecourse.php.

<?php

require "dbconn.php";

$coursecode = $_GET['coursecode'];

$query = "DELETE FROM course WHERE coursecode =".$coursecode;

$results = $connect->query($query);

header("Location: courselisting.php");
?>

这非常令人沮丧,因为我有一个完全相同的示例用于不同的数据库...我只是切换了所有变量名称,但本质上逻辑和语法以及一切都是相同的!

像这样用单引号括起来:

$query = "DELETE FROM course WHERE coursecode='" . $coursecode . "'";

$query = "DELETE FROM course WHERE coursecode='{$coursecode}'";