Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm assuming your delete buttons are simple links. Your links must contain all the information to delete a post. One way would be to pass a post id as a GET variable (e.g. link="myurl.com/posts/delete?id=#").</p> <p>Your script would then at first make sure the current user is allowed to delete the post. For example:</p> <pre><code>$user_id = $_SESSION['user_id']; $post_id = (int) $_GET['id']; if(canDelete($user_id, $post_id)) { // assuming post_id is unique for every post $sql = sprintf("DELETE FROM group_posts WHERE id = %d", $post_id); mysql_query($sql); } </code></pre> <p>Of course, you'd have to implement <code>canDelete($user_id)</code> yourself.</p> <p>By the way, <code>"DELETE FROM group_posts WHERE $current_user = $id"</code> always deletes every record in your table. At first you're comparing if <code>$current_user</code> equals <code>$id</code> and if they do happen to be equal, your query would look something like <code>WHERE 1 = 1</code>. I think you mean <code>"DELETE FROM group_posts WHERE user_id = '$id'"</code></p> <p><strong>EDIT</strong>: It seems you want to use ajax for deleting your posts. I recommend using jQuery or any other proper javascript framework as it saves you time. Here is a link from the jQuery documentation describing <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow noreferrer">how to make an ajax call to the server</a> and a <a href="https://stackoverflow.com/questions/375356/ajax-delete-using-jquery">similar question</a> to help you understand better.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload