我有簡單的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