我有简单的PHP函数生成html链接应删除记录,但删除链接只管理刷新页面。使用PHP删除记录时遇到问题。代码包括
我知道解决方案很简单,但我是PHP新手,所以请有人指点一下我的正确方向?谢谢。非常感谢。
fuctions.php
<?php
include('includes/connect.php');
function getPosts() {
$query = mysql_query("SELECT * FROM posts") or die(mysql_error());
while($post = mysql_fetch_assoc($query)) {
echo "<tr><td>" . $post['Title'] . "</td><td>" . $post['Author'] . "</td><td><a href=\"delete.php?id=" . $post['ID'] . "\">Delete</a><br /><a href=\"edit.php>?id=" . $post['ID'] . "\">Edit</a></td></tr>";
}
}
function deletePost($id) {
$id = (int) $id;
mysql_query("DELETE FROM posts WHERE ID = '$id'") or die(mysql_error());
header("Location: posts.php");
}
?>
delete.php
<?php
include('includes/functions.php');
deletePost($_GET['ID']);
?>
您不会将名为`ID`的参数传递给您的脚本。 – 2011-01-27 14:40:43
deletePost($ _ GET ['id']);区分大小写 – kjy112 2011-01-27 14:46:12