Umair Arshad
Umair Arshad

Reputation: 107

Edit html table row and update It into mysql table using php

I have created update button on my every row in table dynamically using JQuery that successfully editing the table but i don't know how to call php function for updating the database,

i have used juery as

$(document).ready(function () {
      $('.editbtn').click(function() {
    var $this = $(this);
    var tds = $this.closest('tr').find('td').filter(function() {
        return $(this).find('.editbtn').length === 0;
    });
    if ($this.html() === 'Edit') {
        $this.html('Save');
        tds.prop('contenteditable', true);

    } else {
        $this.html('Edit');
        tds.prop('contenteditable', false);
    }
});

questions: how to pass row id to jquery and then update.php page, i am waighting for your help, i hav google it many times but not able to solve my problem

Upvotes: 0

Views: 473

Answers (1)

Rohit Mittal
Rohit Mittal

Reputation: 2104

I will prefer to set id of row on edit button as an attribute, and when you click on edit, you can pick id by this element. Check below code for example:

//Here 1 is id of row which you want to edit
<button class="editbtn" data-id="1">Edit Row</button>

and you can get id on editbtn class click as below:

$('.editbtn').click(function() {
    let rowId = $(this).data("id");
});

And to save updated values, you need to call ajax or need to submit form. You need to pass all data including row id, other fields value in ajax request. I will prefer to use Ajax as it will not load your page and it will look much better for UI.

Hope it will help you.

Upvotes: 1

Related Questions