【发布时间】:2017-05-01 21:07:30
【问题描述】:
我是用 php 制作的。当我选择一个类时,例如我选择了 class9,它会显示 class9 的表格。我还在包含删除按钮的表中插入了一行以删除相应的行。现在我想删除一行购买单击该行中的按钮。我怎样才能做到这一点?
首先我从这个选项中选择一个类,如下图所示;The image from which we select the class
然后将显示相应的表格。
This is the image. When I click on the button, the corresponding row should be deleted.
<?php
include "connection.php";
?>
<!doctype html>
<html>
<head>
<title>KDR</title>
</head>
<body>
<table border="2px" width="50%" height="auto">
<tr>
<th>No</th>
<th>Name</th>
<th>F/Name</th>
<th>Age</th>
<th>Delete</th>
</tr>
<?php
$table = $_POST['formCountry'];
$sql = "SELECT * FROM $table";
$result = $conn->query($sql);
while($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['fname'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td><form method='POST' ><input type='submit' name='deletestudent' value='Delete'/></form></td>";
echo "</tr>";
}
?>
</table>
</body>
【问题讨论】:
-
在您的表单按钮中,您应该给出操作和行的 ID。例如
<form method='POST' action="delete_row.php">和delete_row.php执行删除。 -
好了,那delete_row.php表单中应该写什么代码呢?
-
在
delete_row.php中,您应该编写 MySQL 查询,根据您与表单一起传递的 id 删除行。