PHP / MySQL / AJAX - Update multiple data

update multiple mysql data using checkbox with ajax in php
how to update multiple checkbox values in database in php
php update multiple rows based on checkbox selections
php mysql update multiple rows at once
ajax checkbox update database
how to update multiple records using checkbox in php
update multiple rows php with checkbox value in codeigniter
php update multiple rows in one query

How to update multiple data using AJAX ?

Example :

TableA

id : 1, 2

name : Jack, John

It's only working with id 1, when I am trying to edit name for id 2 it's not working.

I have try with this code but failed.

HTML/PHP :

...

    while($row=mysqli_fetch_array($query)){
    echo'    
    <form class="btn-group">
        <input type="text" class="form-control" name="id_user" id="id_user" data-user="'.$row['id'].'" value="'.$row['id'].'">
        <input type="text" class="form-control" name="id_status" id="id_status" data-status="'.$row['id'].'" value="'.$row['id'].'">
        <button type="submit" id="likestatus" class="btn btn-primary btn-outline btn-xs"><i class="fas fa-thumbs-up"></i></button>
        </form>
    ';
    }

AJAX :

$(document).ready(function(){
    $("#likestatus").click(function(){
    var id_user=$("#id_user").data("user");
    var id_status=$("#id_status").data("status");
        $.ajax({
        url:'status/like-status.php',
        method:'POST',
        data:{
            id_user:id_user,
            id_status:id_status
            },
            success:function(response){
            alert(response);
            }
        });
    });
});

The problem with your code is that ids should be unique, but in the loop you create elements with same id.

Use this in the event handler to find the siblings of the button that has been clicked - closest returns the parent of type form.

$(document).ready(function(){
    $(".btn-primary").click(function(){
        var $form = $(this).closest('form');
        var id_user=$form.find('[name="id_user"]').data("user");
        var id_status=$form.find('[name="id_status"]').data("status");
            $.ajax({
            url:'status/like-status.php',
            method:'POST',
            data:{
                id_user:id_user,
                id_status:id_status
                },
                success:function(response){
                alert(response);
                }
            });
    });
});

You might want to use your own class instead of .btn-primary because this affects all buttons on the page.

PHP / MySQL / AJAX - Update multiple data, The problem with your code is that ids should be unique, but in the loop you create elements with same id. Use this in the event handler to find  MySQL Database MySQL Connect MySQL Create DB MySQL Create Table MySQL Insert Data MySQL Get Last ID MySQL Insert Multiple MySQL Prepared MySQL Select Data MySQL Where MySQL Order By MySQL Delete Data MySQL Update Data MySQL Limit Data PHP XML PHP XML Parsers PHP SimpleXML Parser PHP SimpleXML - Get PHP XML Expat PHP XML DOM PHP - AJAX

Judging from the incomplete PHP, it appears as if you're not assigning to $ruser within your loop. This would mean you're always posting the same id to like-status.php.

PS: Would've posted as comment, but I can't.

Update Multiple Rows with Checkbox in PHP using Ajax Jquery , So, here we have use Ajax for update or edit of Multiple Mysql data by using checkbox Duration: 33:13 Posted: Sep 13, 2018 I found a tutorial that auto submits the form data but all I want to do is add a submit button to pass the data to ajax. My goal is to have a form with multiple inputs and when the user clicks the

Make your ID unique so make them dynamic

 <?php

 $counter = 0;

 while($row=mysqli_fetch_array($query)){
    $counter++;

    echo'    
    <form class="btn-group">
        <input type="text" class="form-control" id="userid_$counter" data-user="'.$ruser['id'].'" value="'.$ruser['id'].'">
        <input type="text" class="form-control" name="id_status" id="status_$counter" data-status="'.$rtimeline['id'].'" value="'.$rtimeline['id'].'">
        <button type="submit" id="likestatus_$counter" class="btn btn-primary btn-outline btn-xs"><i class="fas fa-thumbs-up"></i></button>
        </form>
    ';
    }
?>

Then

<script type="text/javascript">
$(document).ready(function(){
    $('[id^="likestatus_"]').on('click',function(){
         var index = $(this).attr('id').split("_")[1];
    var id_user=$("#user_"+index).data("user");
    var id_status=$("#status_"+index).data("status");
        $.ajax({
        url:'status/like-status.php',
        method:'POST',
        data:{
            id_user:id_user,
            id_status:id_status
            },
            success:function(response){
            alert(response);
            }
        });
    });
});

Update Multiple Selected Records with PHP, Steps in PHP Multiple Rows Update/Delete. Selecting rows using checkbox input. Show form UI for updating table columns. Submit array of row details to PHP. Iterate through row details array to apply update/delete query for each. Ajax CRUD [CReate Update Delete] with PHP and MySQL database In this tutorial, we create a basic commenting system consisting of a form with two input fields: name and comment. A user can add a comment on the page without the page reloading (using Ajax) and this comment is stored in the comments table in the database.

You're using the id's multiple times. Thus your query for var id_user=$("#id_user").data("user"); always finds the first input field on the page. You should avoid using the same id multiple times on one page (see this Question).

You may subscribe to the jQuery submit event of the form and then search for the input fields within that form, to properly extract the id_user and status_user values. For that you have to add an appropriate event listener to the <form> element. To find the form I would recommend adding a css-class like like-status-form.

$(document).ready(function(){
    // We're attaching a submit-event listener to every element with the css class "like-status-form"
    $(".like-status-form").submit(function(event){
       // Form get's submitted
       // Prevent that the Browser reloads the page
       event.preventDefault();

       // Extract the user id and status from the form element (=== $(this))
       var id_user = $(this).find('[name="id_user"]').data('user');
       var id_status = $(this).find('[name="id_status"]').data('status');

       // TODO Perform AJAX Call here
    });
});

To detect the form elements one can use the jQuery Attribute Equals Selector.

Find a working example at https://jsfiddle.net/07yzf8k1/

Update/Delete Multiple Rows using PHP, <?php $host="localhost"; /* Host name */ $username="root"; /* Mysql username */ $password=""; /* Mysql password */ $db_name="test"; /* Database name  How to Insert Data using PHP Ajax - Learn How to Insert Data using PHP Ajax starting from it's overview insert, retrieve, Delete, Filter, upload image etc .

How to Update Multiple Row In PHP, How to Update Multiple rows in Mysql with Checkboxes in PHP using Ajax jQuery​. Update Multiple records using PHP with Checkbox selection. Ajax Edit  I.e. I want the database comment field to be dynamically updated when a teacher is done commenting on a specific student answer. I am not a complete novice, but far from being proficient in java (jquery and ajax, which I use to handle most of my site). I use php and MySQL for serverside and jquery for client side data handling.

Update Multiple Mysql Data using Checkbox with Ajax in PHP دیدئو , How to Update Multiple rows in Mysql with Checkboxes in PHP using Ajax jQuery​. Update Duration: 33:13 Posted: Jan 22, 2020 Learn How to update or edit mysql table data in PHP Ajax using jQuery Dialogify plugin. How to make PHP Ajax Crud application using jQuery Dialogify plugin. Update or Edit Data using PHP Ajax with

Updating multiple MYSQL rows with one submit button - PHP, I am very new to PHP, I don't know how to update multiple MYSQL rows using b) same as above, but use Ajax to action each form submission - only that row is​  Preface. In this tutorial, we will see how to make Ajax work with PHP and MySQL. We will create a small web application. In that, as soon as you start typing an alphabet in the given input field, a request goes to the PHP file via Ajax, a query is made to the MySQL table, it returns some results and then those results are fetched by Ajax and displayed.