我有一些来自数据库的数据,我在最后一列中有一个删除按钮。我想删除单击删除按钮的行。但是,每当我单击删除按钮时,即使单击第一行,也只会删除最后一行。
我的删除功能:
if(isset($_POST['formDelete'])){
if(isset($_POST['quoteid']) && !empty($_POST['quoteid'])){
require_once('config.php');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE)
or die ('Cannot connect to db');
$quoteid = $_POST['quoteid'];
echo "DELETE FROM quotes WHERE quoteid =".$quoteid;
$result = $conn->query("DELETE FROM quotes WHERE quoteid =".$quoteid);
}
表代码:
<form action="<?php $_PHP_SELF ?>" method="post">
<?php
require_once('config.php');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE)
or die ('Cannot connect to db');
$result = $conn->query("SELECT quoteid, quote, cat.catid catid, cat.name cat, scat.catid catid, scat.name scat, author FROM quotes q
INNER JOIN category cat ON q.catid = cat.catid LEFT OUTER JOIN category scat ON q.subcatid = scat.catid order by quoteid");
echo "<table border='1px solid black'>";
echo "<tr><td><b>Category</b></td><td><b>Sub-Category</b></td><td><b>Quote</b></td><td><b>Author</b></td></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>$row[cat]</td><td>$row[scat]</td><td><input type='hidden' id='quoteid' name='quoteid' value=$row[quoteid] />$row[quote]</td><td>$row[author]</td>
<td><input type='submit' name='formDelete' id='formDelete' value='Delete' /></td></tr>";
}
echo "</table>";
?>
</form>
我试图在quoteid的基础上删除。