简体   繁体   English

PHP / MySQL删除记录不会删除

[英]PHP/MySQL Delete Record doesn't Delete

This is driving me crazy! 这真让我抓狂! I have a webpage called course listing where I am using PHP to create a HTML table listing the courses stored in a MySQL database (using Wampserver) 我有一个名为课程表的网页,我在其中使用PHP创建一个HTML表,该表列出了存储在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>

and this prints out a nice HTML table with all the data correctly in it, and a row on the right with the word Delete which is a hyperlink and should allow me to delete a course. 这会打印出一个漂亮的HTML表格,其中正确包含了所有数据,并且在右侧一行显示了单词Delete(是超链接),应该允许我删除课程。 But when I click Delete, it doesn't Delete! 但是,当我单击“删除”时,它不会被删除! Here is my deletecourse.php. 这是我的deletecourse.php。

<?php

require "dbconn.php";

$coursecode = $_GET['coursecode'];

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

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

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

This is super frustrating because I have the exact same example working for a different database... I've just switched out all the variable names, but essentially the logic and syntax and everything is the same! 这让我非常沮丧,因为我有一个完全相同的示例在另一个数据库上工作...我刚刚切换了所有变量名,但是从本质上讲逻辑和语法都一样!

Surround it with single quotes like this: 用单引号将其括起来,如下所示:

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

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

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

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