1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Action with checked records

Discussion in 'PHP' started by raymond222, Jun 18, 2008.

  1. #1
    I have made an output script, that outputs database tables, I've also added a checkbox to each row.

    the checkbox:
    echo "<input type='checkbox' name='teamcheck[]' value='".$data['team_id']."'>";
    PHP:
    And the submit buttone:
    echo"<input type='submit' name='submit' value='Accept' class='button'>";
    PHP:
    What code do I need in order to delete checked record id's from db when user hits "Submit" (I can do the mysql part myself).

    Thanks very much!
     
    raymond222, Jun 18, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    
    <?php
    
    if(isset($_POST['submit'])){
    
       for($x=0;$x<count($_POST['teamcheck']);$x++){   
          
          $list .= ($x == count($_POST['teamcheck'])-1)?$_POST['teamcheck'][$x]:$_POST['teamcheck'][$x].',';
       
       }
       
      $query = 'DELETE FROM team_table WHERE team_id IN ('.$list.')';  
      mysql_query($query); 
    
    }
    
    ?>
    
    PHP:
     
    php-lover, Jun 18, 2008 IP
    viitols likes this.
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    please also check if $_POST['teamcheck'] exists otherwise you get an error if it doesn't exists!
     
    EricBruggema, Jun 18, 2008 IP
    viitols likes this.
  4. raymond222

    raymond222 Active Member

    Messages:
    287
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Thanks m8!
    Rep added...
     
    raymond222, Jun 18, 2008 IP