你可以这样做...这里的关键概念是在数据库中有一个唯一的字段,比如 id 例如你在数据库表中有 id、name、username 和 password 字段,所以看看下面的两种方式
1.使用超链接
<?php
mysql_connect("fostname","username","password");
mysql_select_db("database_name");
$q = mysql_query("SELECT * FROM tbl_name");
if(mysql_num_rows($q)>0)
{
echo"<table>";
echo "<tr><td>name</td><td>action</td></tr>";
while($name = mysql_fetch_assoc($q))
{
?>
<tr><td><?php echo $name['name'];?></td><td><a href="delete.php?id=<?php echo $name['id'];?>">Delete</a></td></tr>
<?php
}
echo "</table>";
}
?>
这就是您在列表页面中所做的......现在查看需要在超链接中定义的路径上的 delete.php
删除.php
<?php
mysql_connect("fostname","username","password");
mysql_select_db("database_name");
$id = $_GET['id'];
$q = mysql_query("delete from tbl_name where id = '$id'");
header("Location: list.php");
?>
2. 使用表格
<?php
mysql_connect("fostname","username","password");
mysql_select_db("database_name");
$q = mysql_query("SELECT * FROM tbl_name");
if(mysql_num_rows($q)>0)
{
echo"<table>";
echo "<tr><td>name</td><td>action</td></tr>";
while($name = mysql_fetch_assoc($q))
{
?>
<tr><td><?php echo $name['name'];?></td><td><form action='delete.php' method='post'> <input type='hidden' value='<?php echo $name["id"];?>'></form></td></tr>
<?php
}
echo "</table>";
}
?>
删除.php
<?php
mysql_connect("fostname","username","password");
mysql_select_db("database_name");
$id = $_POSTs['id'];
$q = mysql_query("delete from tbl_name where id = '$id'");
header("Location: list.php");
?>
(注意:list.php 是您列出所有信息的页面)