toxic27 Posted November 12, 2008 Share Posted November 12, 2008 I recently added a comment script (not mine) to my site and I'm still a beginner at all the MySQL and PHP stuff. Now I have everything done with the 'If..Else' statement to make sure that I'm an admin when I need to delete a comment but now I need a 'delete' link that will delete the comment if needed. Any help? Just ask if you need more details. Link to comment Share on other sites More sharing options...
jlhaslip Posted November 12, 2008 Share Posted November 12, 2008 What code are you working with now?It should be a simple task, actually. One query to find the correct comment and delete it.Sample code here, simply change 'user' with 'comment', or what ever you have used in your DB. // Make the query. $query = "DELETE FROM users WHERE user_id=$id"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. // Print a message. echo '<h1 id="mainhead">Delete a User</h1> <p>The user has been deleted.</p><p><br /><br /></p>'; } else { // If the query did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">The user could not be deleted due to a system error.</p>'; // Public message. } Link to comment Share on other sites More sharing options...
toxic27 Posted November 12, 2008 Author Share Posted November 12, 2008 Well where should I put the code you gave? BTW, I'm using PHP for the main part of it. Here's a snippet of the code.. if($session->isAdmin()){echo '<td align="left" style="text-indent: 14pt" colspan="2"><h5> '.stripslashes($info2->comment).'<br><a href="">DELETE</a></h5><br></td>';}else{echo '<td align="left" style="text-indent: 14pt" colspan="2"><h5> '.stripslashes($info2->comment).'</h5><br></td>';}echo '</tr><tr>'; So that delete link you see, I need that to be the link to click to delete the selected comment. So where do I add your code? Thanks for the help! Link to comment Share on other sites More sharing options...
toxic27 Posted November 12, 2008 Author Share Posted November 12, 2008 EDIT: Oops, double post. Link to comment Share on other sites More sharing options...
jlhaslip Posted November 12, 2008 Share Posted November 12, 2008 In another page, ie: delete_comment.php and the link for the Admin to delete that comment should point to it in the anchor tag. if($session->isAdmin()){echo '<td align="left" style="text-indent: 14pt" colspan="2"><h5> '.stripslashes($info2->comment).'<br><a href="delete_comment.php?comment_id=???">DELETE</a></h5><br></td>';}else{echo '<td align="left" style="text-indent: 14pt" colspan="2"><h5> '.stripslashes($info2->comment).'</h5><br></td>';}echo '</tr><tr>'; This is a difficult thing to explain since you apparently are cutting and pasting code, but the snippet I supplied should be in its own file. I am uncertain what to use for the comment identifier, as well, so I substituted a series of question marks. It is also lacking the 'rest of the file' which you should have to complete the file. (ie: error checking) This is merely one of several files that should be part of a more complete package for the Comment system you have added. I would encourage you to Google for another system to use that includes the Admin side of a more complete Comment system. Link to comment Share on other sites More sharing options...
toxic27 Posted November 12, 2008 Author Share Posted November 12, 2008 Alright, thanks! I'll look into a new one! Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 I tried the code you gave me but it gave me the 'else' error message. Here's all my code..The "Delete" link.. <a href="delete_comment.php?comment_id=$id">DELETE</a> The 'delete_comment.php' page.. <?php include('database.php');?><? // Make the query. $query = "DELETE FROM comments WHERE id=$id"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. header("Location: ../index.php"); } else { // If the query did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">The user could not be deleted due to a system error. <a href="index.php">Home</a></p>'; // Public message. }?> Now for the '$id' thing, is that simply just the unique ID each comment has in the PHPMyAdmin page? Thanks for all the help! Link to comment Share on other sites More sharing options...
jlhaslip Posted November 13, 2008 Share Posted November 13, 2008 Yes, can you list the DB structure here, please. Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 <?mysql_connect("localhost", "kingps3", "***");mysql_select_db("kingps3"); ?> Anything I did wrong? Link to comment Share on other sites More sharing options...
jlhaslip Posted November 13, 2008 Share Posted November 13, 2008 not the connection info, the design and layout of the Table for comments. Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 Oh, oops.. here you go..Didn't know how to actually copy & paste the table contents so I took a print screen picture of it.. Link to comment Share on other sites More sharing options...
jlhaslip Posted November 13, 2008 Share Posted November 13, 2008 See the 'id' column? That would be the sequence number that you are trying to delete, right? Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 Yup. I put '$id' where needed though (I think) in the delete_comment.php file so shouldn't that call out a specific comment? Link to comment Share on other sites More sharing options...
jlhaslip Posted November 13, 2008 Share Posted November 13, 2008 Try this: // Check for a valid user ID through GETif ( (isset($_GET['comment_id'])) && (is_numeric($_GET['comment_id'])) ) { $id = $_GET['comment_id']; } else { // No valid ID, kill the script. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; include ('./includes/footer.html'); exit();} // Make the query. $query = "DELETE FROM comments WHERE id=$id"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. // Print a message. echo '<h1 id="mainhead">Delete a User</h1> <p>The user has been deleted.</p><p><br /><br /></p>'; } else { // If the query did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">The user could not be deleted due to a system error.</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. } Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 Well, include/footer.php doesn't exist. Should I just remove that? Link to comment Share on other sites More sharing options...
jlhaslip Posted November 13, 2008 Share Posted November 13, 2008 Yup,sorry I missed that. Cut and paste from another script. Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 It's coming up with the error message. This is the code I'm using.. <html><head></head><body><?mysql_connect("localhost", "kingps3", "**");mysql_select_db("kingps3"); // Check for a valid user ID through GETif ( (isset($_GET['comment_id'])) && (is_numeric($_GET['comment_id'])) ) { $id = $_GET['comment_id']; } else { // No valid ID, kill the script. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; exit();} // Make the query. $query = "DELETE FROM comments WHERE id=$id"; $result = @mysql_query ($query); // Run the query. if (mysql_affected_rows() == 1) { // If it ran OK. // Print a message. echo '<h1 id="mainhead">Delete a User</h1> <p>The user has been deleted.</p><p><br /><br /></p>'; } else { // If the query did not run OK. echo '<h1 id="mainhead">System Error</h1> <p class="error">The user could not be deleted due to a system error.</p>'; // Public message. echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message. }?></body></html> Link to comment Share on other sites More sharing options...
jlhaslip Posted November 13, 2008 Share Posted November 13, 2008 Okay, just checking, but how is the comment list created? I assume you are getting the "The user could not be deleted due to a system error.".Is there a Comment_id for each comment? or is it asking to find comment_id= $id ?The page that list the Comments needs to add the correct 'id' value for each listed Comment. The value should match the phpmyadmin screen you posted above.*edit*You really need to remove the password and DB name up in that post. Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 Oops, last time I deleted the password but this time I forgot. No worries though, I changed my pw and all for PHPMyAdmin. Thanks for letting me know!Alright, and back to the comment problem. What do you mean by an ID for each comment? When anytime anyone posts a comment, an ID is given to the comment. Is that what you meant? Link to comment Share on other sites More sharing options...
jlhaslip Posted November 13, 2008 Share Posted November 13, 2008 correct Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 Yeah, everyone time a comment is made, an ID number (diff. from the rest) is given to that specific comment. Link to comment Share on other sites More sharing options...
jlhaslip Posted November 13, 2008 Share Posted November 13, 2008 So the script that lists the comments out, and where the 'delete' link for that comment is, should identify each line by using the comment table "id", right? Is the script doing that?It would help to see a link to the demo page. Then i could determine whether the unique comment_id is there or not. Is this site "live" or on your local machine only? Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 Here you go:http://www.kingps3.com/_r2.phpIf you scroll down, you will see some comments. If you're logged onto an admin account, you will see the delete link right below each comment which has this code: <a href="delete_comment.php?comment_id=$id">DELETE</a> If you want I can give you an admin account really quick so you can see the delete link. Link to comment Share on other sites More sharing options...
jlhaslip Posted November 13, 2008 Share Posted November 13, 2008 okay, registering now.Oops! Under Maintenance... can not register. Can you create a new admin account and send the log-in by PM please. Link to comment Share on other sites More sharing options...
toxic27 Posted November 13, 2008 Author Share Posted November 13, 2008 Alright, sent. Sorry about that, my user system is acting up today. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.