如何删除php MySQL数据库中的记录

如何删除php MySQL数据库中的记录,php,mysql,sql,database,html-table,Php,Mysql,Sql,Database,Html Table,因此,我希望能够在PHP中使用表中每一行旁边的按钮删除一条记录。我在任何地方都找不到一个能帮助我解决问题的好教程,我真的被卡住了,不知道该怎么办 如果有人能告诉我该怎么做,下面是我的代码: <!DOCTYPE html> <html> <head> <title>PCSS Grad Gown</title> <link rel="stylesheet" type="text/css" href="Grad_Gown_Report.

因此,我希望能够在PHP中使用表中每一行旁边的按钮删除一条记录。我在任何地方都找不到一个能帮助我解决问题的好教程,我真的被卡住了,不知道该怎么办

如果有人能告诉我该怎么做,下面是我的代码:

<!DOCTYPE html>
<html>
<head>
<title>PCSS Grad Gown</title>
<link rel="stylesheet" type="text/css" href="Grad_Gown_Report.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>

<style>

  body {
      background-image: url("http://www.miguelmontalban.com/wp-content/uploads/2015/11/uSr9bZA-fancy-background-images.jpg");
  }

  td {
      color: white;
  }

  .Grad_Table {
      color :white;
  }
 </style>
</head>
<body>

<?php
    $servername = "Private";
    $username = "Private";
    $password = "Private";
    $dbname = "Private";


    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);

    $order;
} 
   $order = $_GET['order'];
    if (!$order) {
        $order = "name";
    }

    $sql = mysqli_query ($conn, "SELECT * FROM Information ORDER By $order");

    ?>

    <div class="table-responsive" id="grad_table">

        <br>
        <br>

    <table class="Grad_Table" width="100%" border="12px">
        <thead>
            <tr>
                <td><a href="Grad_Gown_Report.php">Name:</a></td>
                <td><a href="Grad_Gown_Report_2.php">Student #:</a></td>
                <td>Homeform #:</td>
                <td>Unit:</td>
                <td>Height:</td>
                <td>Size:</td>
                <td></td>



            </tr>

        </thead>

        <tbody>
            <?php

            while ($rows = mysqli_fetch_assoc($sql)) {
            ?>

            <tr>
    <td><?php echo $rows['Name'];?></td>
    <td><?php echo $rows['Studentnum'];?></td>
    <td><?php echo $rows['Homeform'];?></td>
    <td><?php echo $rows['Unit'];?></td>
    <td><?php echo $rows['Height'];?></td>
    <td><?php echo $rows['Size'];?></td>









            </tr>

            <?php


            }


            ?>
        </tbody>


    </table>

    </div>




</div>
</body>
</html>

毕业礼服
身体{
背景图像:url(“http://www.miguelmontalban.com/wp-content/uploads/2015/11/uSr9bZA-fancy-background-images.jpg");
}
运输署{
颜色:白色;
}
.Grad_表{
颜色:白色;
}


Homeform#: 单位: 高度: 尺寸:

我可以从数据库中完美地检索数据,其他一切都可以按照我的要求正常工作。我唯一需要的是delete函数。我尝试过很多东西,包括关于W3学校的教程,我尝试过面向对象和过程的方法,但它们都给了我同样的错误。我确实更喜欢一个单独的delete.php文件,但我对任何有效的方法都没有意见。

创建一个php脚本,该脚本按ID删除条目,然后在创建表行时,输出一个指向具有给定ID的脚本的链接

// Using your code as a reference
while($rows = mysqli_fetch_assoc($sql)) : ?>
  <tr>
    <td>
      <a href="/somepath/delete_entry.php?entry_id=<?php echo $row['Id']; ?>">Delete Entry</a>
    </td>
  </tr>
endwhile;
//使用您的代码作为参考
而($rows=mysqli\u fetch\u assoc($sql)):?>
结束时;
删除脚本的外观如下所示:

<?php
  // Perform any user auth here ...

  // Connect to mysql here ...

  if(!isset($_GET['entry_id'])) {
    die('You need to provide an ID');
  }

  $id = $_GET['entry_id'];

  // Ensure the ID is an integer or an int-like string
  if(!ctype_digit("$id")) {
    die('Invalid ID provided');
  }

  // We've verified that if $id is a string, it is an int-like string; otherwise, it is actually an integer.
  // Let's convert it to an actual integer
  $id = (int) $id;

  // At this point, if you have users and users own this resource, you might check to make sure they actually have permission to delete the requested resource.

  $query = "DELETE FROM Information WHERE Id = $id;";
  $mysqli->query($query);

  // If this is a rest API, you can just end with HTTP 200 (let the script die); 
  // otherwise, redirect them to the page they should see after performing this action
  header('location: /view_something.php');

我将如何创建通过ID@AsadKhan-更新了我的答案我不知道为什么,但它仍然不起作用你有什么错误?您是否修改了我的代码以适合您的应用程序?当我单击“删除”按钮时,它会将我带到设置模具ID的页面