html - How to delete multiple data entries using checkboxes in PHP? -


ok know question has been asked before , have run through lot of different answers... still can't working right.

this higher in code threads displayed. nested inside of echo displaying table. except marked comments, others not next code shown. wanted code highlight right way.

 <?php //more code here~  while ($x = $s->fetch_object()){  $c = $c==1?2:1;  echo '<tr> <td style="border: 1px solid #1f2a19; padding-left: 5px; padding-right: 5px; " class="color1" width="1%" nowrap> <input type="checkbox" class="check" name="check[]" value="'.($x->id).'" /></td>  //more displaying table code here. ';  }$s->close(); ?> 

lower down in code near buttons appear @ end of page have this.

<?php if (u::isstaff())  { ?> <!--this here because file .php , of code php.     little html used.-->      <input type="submit" name="delete" value="delete"/>   <?php // same one. in code. if(isset($_post['delete'])) {  $cnt=array(); $cnt=count($_post['check']);  for($i=0;$i<$cnt;$i++)   {      $del_id=$_post['check'][$i];      $query=("delete forumposts 'thread'='$del_id'");     mysql_query($query);     $query=("delete forumthreads 'id'='$del_id'");      mysql_query($query);   } //for } //ispost delete } //isstaff ?> 

the goal of code grab thread id number checkboxes , run through deletion function when button pressed. giving staff members power delete multi threads in board @ once.

this code works delete single thread , basing multi delete thread function on. in different file "thread.php"

 <?php if ($_get['act'] == 'deletethread'){      if (!u::ismod()) return f::deny();      $db->query("delete forumposts         `thread`='{$thread->id}'");      if ($db->error) die(trigger_error($db->error) );      $db->query("delete forumthreads         `id`='{$thread->id}'");      if ($db->error) die(trigger_error($db->error) );      s::go('board?i='.$thread->board);   }?> 

========================================================

so think have failed on button... never learned java before. middle section looks now. have feeling still doing delete part wrong well.

<input type="submit" name="delete" value="delete"/>  <?php  if(isset($_post['check_list'])){  $cnt=array(); $cnt=count($_post['check_list']);  for($i=0;$i<$cnt;$i++)   {     $ids = implode(',', $_post['check_list']);      mysqli_query("delete forumposts id in ($ids)");     mysqli_query($query);     mysqli_query("delete forumthreads id in ($ids)");     mysqli_query($query);   } //for } //ispost delete } //isstaff ?> 

echo '<tr>         <td style="border: 1px solid #1f2a19; padding-left: 5px; padding-right: 5px; " class="color1" width="1%" nowrap>            <input type="checkbox" class="check" name="check[]" value="'.($x->id).'" />         </td>  

in php file:

$ids = implode(',', $_post['check']);  mysqli_query("delete forumposts id in ($ids)"); 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -