php - Delete ROWS from one table and then INSERT into another TABLE in MYSQLI -


i have 2 table names called "message" , "trash"

in "message" table, i've data in table format contains (to, subject, msg, date) , applied checkall functionality checkbox using jquery,

now want perform when delete row moves row table i.e. "trash"

delete query working want modify code... here's code -

<form action="delete.php" method="post" name="data_table"> <table class="table table-hover table-striped"> <tbody> <tr style="background-color:#222d32;"> <td><input type="checkbox" id="check_all" value=""></td> <td><input name="submit" type="submit" value="delete" id="submit" class="btn btn-default btn-sm"></td> <td></td> <td></td> </tr>  <tr> <td><input type="checkbox" value="<?php echo $rw['id']; ?>" name="data[]" id="data"></td> <td><b><?php echo $rw['fto']; ?></td> <td><b><?php echo $rw['subject']; ?></b></td> <td><b><?php echo $rw['date']; ?></b></td> <tr> </tbody> </table> </form> 

and here's delete.php file

<?php require_once("config.php"); if(isset($_post['submit'])) {      $id_array = $_post['data']; // return array     $id_count = count($_post['data']); // count array      for($i=0; $i < $id_count; $i++) {         $id = $id_array[$i];         $query = mysqli_query($con, "delete `message` `id` = '$id'");         if(!$query) { die(mysqli_error()); }     }     header("location: sent.php"); // redirect after deleting } ?> 

here's js file included @ top

jquery(function($) {     $("form input[id='check_all']").click(function() { // triggred check          var inputs = $("form input[type='checkbox']"); // checkbox          for(var = 0; < inputs.length; i++) { // count input tag in form             var type = inputs[i].getattribute("type"); //  type attribute                 if(type == "checkbox") {                     if(this.checked) {                         inputs[i].checked = true; // checked                     } else {                         inputs[i].checked = false; // unchecked                      }                 }         }     });      $("form input[id='submit']").click(function() {  // triggred submit          var count_checked = $("[name='data[]']:checked").length; // count checked         if(count_checked == 0) {             alert("please select row(s) delete.");             return false;         }         if(count_checked == 1) {             return confirm("are sure want delete?");         } else {             return confirm("are sure want delete?");           }     }); }); 

in delete.php should write below

<?php require_once("config.php"); if(isset($_post['submit'])) {  $id_array = $_post['data']; // return array $id_count = count($_post['data']); // count array  for($i=0; $i < $id_count; $i++) {     $id = $id_array[$i];     $query = mysqli_query($con, "insert trash select * `message` `id` = '$id'");     $query = mysqli_query($con, "delete `message` `id` = '$id'");         if(!$query) { die(mysqli_error()); }     }     header("location: sent.php"); // redirect after deleting } ?> 

Popular posts from this blog