5

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 ....');
                      })
                  }
                }
              }
            });
});
5
  • jquery is client side, mysql is server side. You have to use ajax from the client, that calls a php script on the server that does the database query. Commented Dec 16, 2016 at 17:43
  • 1
    You should probably show your php code then, more specifically your mysql query. Commented Dec 16, 2016 at 17:43
  • where should pid1 come from?? I guess you want it to be show_id, right? Commented Dec 16, 2016 at 17:46
  • @Nytrix Yep, right, my comment points to the question topic! There is no way to delete something with jquery in a mysql database. Sometimes i get a little nerdy :) One of my bad comments i thing Commented Dec 16, 2016 at 17:48
  • @JustOnUnderMillions I thought that, I can get a little picky. We keep eachother in balance :) Commented Dec 16, 2016 at 17:49

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.