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
https://forums.phpfreaks.com/topic/153867-solved-allowing-user-to-delete-records/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.