希望有人可以帮助我,我想我没有正确调用我的函数。 我正在尝试从我的数据库中检索一些数据,并将删除链接附加到正在检索的每个项目,这样当我单击删除时,它就会删除具有删除功能的特定项目。
我从数据库检索项目的代码如下。
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("uloaku", $con);
$count = 1;
$y = mysql_query("SELECT * FROM transaction");
if(mysql_num_rows($y) != 0){
echo "<table bgcolor=\"white\" width=\"1000\" bordercolor=\"grey\" border=\"5\" >";
echo "<tr>
<td align=\"center\">No</td>
<td align=\"center\">Date</td>
<td align=\"center\">Current Balance</td>
<td align=\"center\">Avaliable Balance</td>
<td align=\"center\">Account Status</td>
<td align=\"center\">Delete Account</td>
</tr>";
while ($z = mysql_fetch_array($y, MYSQL_BOTH)){
echo "<tr>
<td align=\"center\">".$count++."</td>
<td align=\"center\">".$z[1]."</td>
<td align=\"center\">".$z[2]."</td>
<td align=\"center\">".$z[3]."</td>
<td align=\"left\" width=\"300\">".$z[4]."</td>
<td><a href=\"delete.php\">delete</a></td>
</tr>";
}
echo "</table>";
}
?>
以及我要删除的代码
<?php
session_start();
$con = mysql_connect("localhost","root","");
mysql_select_db("uloaku", $con);
$id = $_GET['id'];
$sql = mysql_query("DELETE FROM transaction WHERE id='$id' LIMIT 1") or die (mysql_error());
header("Location: vacct.php");
?>
我知道我错过了这里的逻辑,希望有人能指导我或告诉我简单的出路。目前我可以成功地从数据库中检索我的项目,我唯一的问题是每次点击删除按钮时都能够应用删除功能。
最佳答案
当您点击删除链接时,您必须传递id
:
<a href=\"delete.php?id=$z[theIdKey]\">
关于Php从mysql数据库中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12339766/