Jump to content

Deleting Tag Entries from Database


CMellor

Recommended Posts

Hey.

I've made a tag board, and an ACP to delete/ban posts/users, but I can't for some reason get to be able to delete the selected posts when I click delete on the tag.

Here's my code, it aint long.

[code]<?php
/* TAGS */
if($do = "interactive_tag_board_tags"): ?>
<table width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td class="header">Tags</td>
  </tr>
  <tr>
    <td class="row1">
    <table width="99%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="5%" align="center" class="header">ID</td>
        <td width="25%" align="center" class="header">Poster</td>
        <td width="55%" align="center" class="header">Tag</td>
        <td width="15%" align="center" class="header">Options</td>
      </tr>
      <?php $query = mysql_query("SELECT * FROM $dbname.tags ORDER BY id DESC");
      while($row = mysql_fetch_array($query)) { ?>
      <tr>
        <td align="center" class="row2"><?=$row['id']?></td>
        <td align="center" class="row2"><?=$row['poster']?></td>
        <td class="row2"><?=$row['tag']?></td>
        <td align="center" class="row2"><input type="hidden" name="id" value="<?=$row['id']?>" />
          <a href="?do=interactive_tag_board_tags&delete=<?=$row['id']?>"><img src="../img/delete.gif" /></a></td>
      </tr>
      <?php } ?>
    </table>
    </td>
  </tr>
</table>
<?php /* END TAGS */ endif; ?>[/code]

Can anyone give me a quick code that let's me delete the tag I select? I put a hidden input in their, thinking maybe that could be used somehow.

Would really appriciate the help, thanks a lot.

Chris.
Link to comment
Share on other sites

The actual code I posted isn't the problem, though thanks for pointing that error out. I just asked if someone could write a little bit of code to allow me to delete my selected tag. I know it's asking a bit, but I know it can be done with only a couple of line's of code.

I did try this, but it said "delete" before I even did anything

[code]if($_GET['delete'] == $row['id']) {
  $refresh = mysql_query("DELETE FROM $dbname.tags WHERE id = '".$row['id']."'");
    if($refresh) { echo('deleted'); }
  }[/code]
Link to comment
Share on other sites

At start of your code
[code]<?
if($_GET['do'] == "interactive_tag_board_tags"):

        if (isset ($_GET['delete'])) {
               $delid = $_GET['delete'];
               mysql_query("DELETE FROM $dbname.tags WHERE id = '$delid' ");
        }
?>[/code]
Link to comment
Share on other sites

Thanks for the help but that didn't do anything. Here's what I have.

[code]<?php
/* TAGS */
if($do == "interactive_tag_board_tags"):
  $query = mysql_query("SELECT * FROM $dbname.tags ORDER BY id DESC");
    if(isset($_GET['delete'])) {
      mysql_query("DELETE FROM $dbnames.tags WHERE id = '".$_GET['delete']."'");
    }
?>
<table width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td class="header">Tags</td>
  </tr>
  <tr>
    <td class="row1">
    <table width="99%" cellspacing="0" cellpadding="0">
      <tr>
        <td width="5%" align="center" class="header">ID</td>
        <td width="25%" align="center" class="header">Poster</td>
        <td width="55%" align="center" class="header">Tag</td>
        <td width="15%" align="center" class="header">Options</td>
      </tr>
      <?php while($row = mysql_fetch_array($query)) { ?>
      <tr>
        <td align="center" class="row2"><?=$row['id']?></td>
        <td align="center" class="row2"><?=$row['poster']?></td>
        <td class="row2"><?=$row['tag']?></td>
        <td align="center" class="row2"><input type="hidden" name="id" value="<?=$row['id']?>" />
          <a href="?do=interactive_tag_board_tags&delete=<?=$row['id']?>"><img src="../img/delete.gif" /></a></td>
      </tr>
      <?php } ?>
    </table>
    </td>
  </tr>
</table>
<?php /* END TAGS */ endif; ?>[/code]

Nothing happens when I click delete.
Link to comment
Share on other sites

You are now querying the tags table before the deletion has been executed. Move it to after the delete query

[code]if($do == "interactive_tag_board_tags"):
  
    if(isset($_GET['delete'])) {
      mysql_query("DELETE FROM $dbnames.tags WHERE id = '".$_GET['delete']."'");
    }

    $query = mysql_query("SELECT * FROM $dbname.tags ORDER BY id DESC");
?>[/code]
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.