我正在尝试从我的 MySQL 数据库中删除我的数据行。
下面是打印带有关键字的表的结果的查询。看这张照片,看看我的结果是如何显示的:
我成功地从我的 addKeywordTable 中获取了我的数据,但是我无法进行删除。这是我的 index.php 页面,它显示了单击以激活删除的输入按钮:
<?php
include 'db.php';
$sql = mysqli_query($con,"SELECT * FROM addKeywordTable ORDER BY
Keyword_Name ASC");
print <<<HERE
<table id="home">
HERE;
while ($row = mysqli_fetch_array($sql))
{
$key = $row['Keyword_Name'];
print <<<HERE
<tr><td>
<form method="post" formenctype="multipart/form-data" formmethod="POST"
value="Delete" action="deleteKey.php">
<tr>
<input type="hidden" name="sel_key" value="$id">
<input type="submit" name="delete" value=" Delete " id="deleteKey" > $key
<hr/></tr>
</form></td></tr>
HERE;
}
print "</tr></table></body></html>";
?>
当您单击“删除”按钮时,您将进入确认页面 deleteKey.php,如下所示:
<?php
require 'db.php';
$sel_key = $_POST[sel_key];
//SQL statement to select information
$sql = "SELECT * FROM addKeywordTable WHERE keyID = $sel_key";
//loop through record and get values
while ($key = mysqli_fetch_array($result)) {
$id = $key['Keyword_Name'];
} // end while loop
$pageTitle = "Delete a Keyword";
print <<<HERE
<div id="form1profile">
<h2>Are you sure you want to delete this record?<br/>
It will be permanently removed:</h2>
<ul>
<li>Keyword Category:<br/></li>
$key;
</ul>
<p><br />
<form method="post" action="reallyDelete.php">
<input type="hidden" name="id" value="$id">
<input type="submit" name="reallydelete" value="Confirm Delete" />
<input type="button" name="cancel" value="cancel"
onClick="location.href='addProfile.php'" /></a>
</p></form></div>
HERE;
// close else
?>
确认删除后,您将进入确认页面:“reallyDelete.php”。这是我遇到问题的页面。出于某种原因,我的变量不显示行/关键字名称的内容。
我的数据库中只有 2 列:KeyID 和 Keyword_Name
这是删除确认页面。我如何将 $id 传递给数据库以删除关键字/记录。
<?php
include 'db.php';
$id = $_POST[id];
$sql = "SELECT * FROM addKeywordTable WHERE Keyword_Name = '$id'";
while ($row = mysqli_fetch_array($result)) {
$id = $row['Keyword_Name'];
} // end while loop
print "<p> $row has been permanently deleted.</p>";
$sql="DELETE FROM addKeywordTable WHERE Keyword_Name = '$id'";
echo "<meta http-equiv='Refresh' content='2; URL=addKeyword.php'>";
?>
对此的任何帮助都会很棒。下面是我的 addKeywordTable 的 sql 表的屏幕截图