Little Game Script Problem

Discussion in 'PHP' started by poblo10, Jul 31, 2010.

  1. #1
    Just coding a lil game, but what i want this to do is allow users to add "enemies" to there list, but i also want them to be able to remove enemies. The way i have it set up right now is when they click the [X] that displays above the enemy name is that it deletes all the enemies

    What i want it to do is when they click the [X] is just delete THAT entry not every row in the database. Anyone help?

    <?php
    $sql = mysql_query("SELECT * FROM enemy");
    while($row = mysql_fetch_array($sql))
    {
      $ename = $row['ename'];
      $evill = $row['evill'];
      $delete = mysql_query("DELETE FROM enemy WHERE evill='$evill'");
      echo "<b><a href='?$delete'>[X]</a></b>";
      echo "<br /><b>Enemy:</b> " . $ename;
      echo "<br /><b>Village:</b> " . $evill;
      echo "<br />";
      echo "<br />";
    
    }
    ?>
    PHP:
    It displays like this

    [X]
    Enemy: Enemies Name
    Village: Enemies Village

    .etc

    Basicly just keeps going as far as they add entries.
     
    poblo10, Jul 31, 2010 IP
  2. Martin K

    Martin K Active Member

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Try this it should help
     
    Last edited: Aug 1, 2010
    Martin K, Aug 1, 2010 IP
  3. XoC

    XoC Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Just thought i'd add onto what Martin said, you'll probably want to change deleting $evil to $ename so that's it's removing the person rather than the entire village.

    Also make sure you sanitize the input!
     
    XoC, Aug 3, 2010 IP
  4. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    probably worth checking it's the user themselves doing the deleting as well.

    So add in user_id and ename to the delete from enemy query and all should be good
     
    themullet, Aug 3, 2010 IP
  5. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #5
    another thing you will want to do is associate the enemy or allies in the DB to that specific person that added them or is deleting them.

    as numerous people will have same or similar enemies, or allies

    so have it store the persons id that is adding them as a enemies or allies then you can be more specific when deleting them so it dont delete all at one time.
     
    lowridertj, Aug 4, 2010 IP