Jump to content

[SOLVED] Allowing User to Delete Records


Bopo

Recommended Posts

Hi

 

Well this more of an advice question really, basically I have build a simple CMS, users can comment on articles, and obviously I have an admin section which allows the administrator to view all comments, which are output into a table.

 

Naturally I want to allow the administrator to remove comments, however from a technical view the only method I could actually think of & implement right now would be to have a textbox, the admin types the comment id into it and clicks a button which deletes the comments, I know this solution has many flaws but I'm looking for a better method, I can think of dozens however I don't know how to implement them from a coding point of view.

 

Here is the code I'm currently using

 

<?php 

include("blogconnect.php");

$sql = "SELECT * FROM comments ORDER BY id DESC LIMIT 0, 10";

echo '<table width="250" border="1">';
echo '<tr>
  <td class="bh">ID</td>
  <td class="bh">Name</td>
  <td class="bh">Comment</td>
  <td class="bh">Date</td>
   </tr>';

$query = mysql_query($sql, $connect) or die (mysql_error()); 
while ($row = mysql_fetch_assoc($query)) {   //this is where the error is highlighted
echo '<tr>';	
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['author'] . '</td>';
echo '<td>' . $row['comments']. '</td>';
echo '<td>' . $row['date']. '</td>';
echo '</tr>';
}


echo '</table>';

?>

Link to comment
Share on other sites

You could always just make a certain page in the admin panel that lists all comments in an array from the database.

Then have another page that has a form on it with blank text fields.

Whatever comment name link they click on would take the admin to this new page based on the name and id of the comment, where the text fields could be populated with the info for that certain topic with a delete button at the bottom.

 

When the delete button is clicked, remove all instances of that comment from the database.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.