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($quer开发者_JAVA技巧y)) {
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']);
?>
In your delete.php
file, you call:
deletePost($_GET['ID']);
However, in your link you use:
delete.php?id=
It is a case issue, make them both be upper case ID
or lower case id
.
Check your casing.
You are setting the GET
paramets name to id
while checking for ID
Print your sql delete command before executing and it I suppose will answer your question.
精彩评论