1

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']);
?>
2
  • you don't pass parameter called ID to your script. Commented Jan 27, 2011 at 14:40
  • deletePost($_GET['id']); case sensitive Commented Jan 27, 2011 at 14:46

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Check your casing.

You are setting the GET paramets name to id while checking for ID

Comments

0

Print your sql delete command before executing and it I suppose will answer your question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.