Jump to content


Photo

Deleting Tag Entries from Database


  • Please log in to reply
5 replies to this topic

#1 CMellor

CMellor
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationLeeds, UK

Posted 08 April 2006 - 04:40 PM

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.

<?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; ?>

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.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 April 2006 - 04:44 PM

The comparison operator for equals is "==" not "=". You have used the "=" in your "if" statement, change it to a "==" and see if that helps.

Ken

#3 CMellor

CMellor
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationLeeds, UK

Posted 08 April 2006 - 04:59 PM

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

if($_GET['delete'] == $row['id']) {
  $refresh = mysql_query("DELETE FROM $dbname.tags WHERE id = '".$row['id']."'");
    if($refresh) { echo('deleted'); }
  }


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 08 April 2006 - 07:43 PM

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

        if (isset ($_GET['delete'])) {
               $delid = $_GET['delete'];
               mysql_query("DELETE FROM $dbname.tags WHERE id = '$delid' ");
        }
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 CMellor

CMellor
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts
  • LocationLeeds, UK

Posted 09 April 2006 - 12:10 AM

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

<?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; ?>

Nothing happens when I click delete.

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 09 April 2006 - 09:24 AM

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

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");
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users