I Have simple PHP functions that produce html links which should delete a record, however the delete link only manages to refresh the page.
I know the solution is simple but I am new to PHP so could somebody please be kind enough to point me in the right direction? thank you. help greatly appreciated.
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']);
?>