2011-01-27 55 views
1

我有簡單的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']); 
?> 
+0

您不會將名爲`ID`的參數傳遞給您的腳本。 – 2011-01-27 14:40:43

+0

deletePost($ _ GET ['id']);區分大小寫 – kjy112 2011-01-27 14:46:12

回答

4

在你delete.php文件,你稱:

deletePost($_GET['ID']); 

然而,在你的鏈接使用:

delete.php?id= 

這是一個個案問題,使它們都是大寫ID或小寫id

0

檢查你的套管。

您的GET paramets名字爲id同時檢查ID

0

打印您的SQL執行前刪除命令的,我知道會回答你的問題。