Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Remove Database Entry (PHP)

    On my website, I recently added a comment system for games. What I want to do is add an 'X' button so that users can delete their comments if they choose. Before I can do this, I need a PHP function that will remove that specific comment from the database. How should I go about this?

    Here is how the comment is added to the database:
    PHP Code:
    $tuturl $_POST["tuturl"];
    $tutid2 $_POST["tutid2"];
    $name $_POST["name"];
    $url $_POST["url"];
    $email $_POST["email"];
    $message $_POST["message"];
    $user_id $_POST["user_id"];

    $sendcomment mysql_query("INSERT INTO comments SET tutorialid='$tutid2', name='$name', url='$url', email='$email', comment='$message', date=now(), user_id='$user_id' "); 
    Any help would be greatly appreciated!

    *Note - More Detail*
    Here's the tutorial I followed for my comment system:
    http://www.zimmertech.com/tutorials/...t-tutorial.php

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I found this on another site
    PHP Code:
    $sql_delete_byindex "DELETE FROM `$mysql_table` WHERE `index` = '".$rec_index."' AND `key` = '".$key."'"
    I know very little about my sql, only started working with it a couple weeks ago. Could I use this? Something like:

    PHP Code:
    function delete_comment()
    {
      
    // Connect to MySQL

      
    $comment_id some code to get the comment id;
      
    $tutorialid some code to get the tut id;
      
    $user_id $user->data['user_id'];
      
    $mysql_table 'comments';
      
      
    $sql_delete_by_id mysql_query("DELETE FROM `$mysql_table` WHERE `commentid` = '".$comment_id."' AND `tutorialid` = '".$tutorialid."' AND `user_id` = '".$user_id."'  ") or die(mysql_error()); 
      

    Would this code work? I'm a bit worried about testing it, I don't want to mess anything up.
    Last edited by Tech.Inno; 07-07-2011 at 07:37 PM.

  • #3
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by Tech.Inno View Post
    I'm a bit worried about testing it, I don't want to mess anything up.
    All testing/development is normally done in a testing environment not a "live" production environment.

    One option is to download a free ready to go ("just add water") web server, like XAMPP, and do all your testing on that. XAMPP comes with Apache, PHP and MySQL preconfigured to work together.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •