Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i delete row tables in mysql with jquery?

Tags:

I want to delete specific rows in mysql by jquery. It works on the first row, but in the second row, nothing happens.

This is my HTML code:

     <td><p data-placement="top" data-toggle="tooltip" title="Delete">
       <button id="dele_com" class="btn btn-danger btn-xs" name="<?php echo $rows['companyID']; ?>">
        <span class="icon-trash"></span>
       </button></p>
     </td>

and this is my jquery code:

$("#dele_com").on("click", function(event) {        
 var show_id = this.name;
            alert(show_id);
            bootbox.dialog({
              message: "Are you sure you want to Delete this account ?",
              title: "<i class='icon-trash'></i> Delete !",
              buttons: {
                success: {
                  label: "No",
                  className: "btn-success",
                  callback: function() {
                     $('.bootbox').modal('hide');
                  }
                },
                danger: {
                  label: "Delete!",
                  className: "btn-danger",
                  callback: function() {
                      $.post('update_delete.php', { 'pid1':pid1 })
                      .done(function(response){
                          window.location.href= "modification.php";
                      })
                      .fail(function(){
                          bootbox.alert('Something Went Wrog ....');
                      })
                  }
                }
              }
            });
});
like image 495
AboYousef16 Avatar asked Dec 16 '16 17:12

AboYousef16


People also ask

How do you delete a row in a table using jQuery?

The jQuery remove() method is used to remove a row from HTML table. jQuery remove() Method: This method removes the selected elements alongwith text and child nodes. This method also removes data and events of the selected elements. Parameters: It accepts single parameter selector which is optional.

How do you delete a row in a table using Ajax?

$id); $totalrows = mysqli_num_rows($checkRecord); if($totalrows > 0){ // Delete record $query = "DELETE FROM authors WHERE id=". $id; mysqli_query($con,$query); echo 1; exit; }else{ echo 0; exit; } } echo 0; exit; ?> ✌️ Like this article?


1 Answers

Here you have specified the id #dele_com and that will be the same for every row. So when you click on the delete button it will find the first id of your table and performs click.

You have to use class selector instead of id then it will work

like image 88
Jaymin Panchal Avatar answered Sep 22 '22 16:09

Jaymin Panchal