Update mysql with batch grid not updating

3 posts, 0 answers
  1. johaswe
    johaswe avatar
    1 posts
    Member since:
    Jul 2007

    Posted 13 Aug 2013 Link to this post

    Hi,

    I have been following several examples for the CRUD setup but seems i cannot get it to work.
    Below is the code i run -
    1. It reads perfectly.
    2. It calls the save method
    3. It sends the correct data to the update php file.
    4. If i take the link with the head data from firebug and paste into the browser it do update the records
    5. if i do the update from the grid it gets a 200 ok but nothing is updated in the database.

    Where do i go wrong?
    First is my html code
    Next is my php file for update.

                <div id="example" class="k-content">
                <div id="grid"></div>
     
    <divclass="console"></div>
     
                <script>
                    $(document).ready(function (options) {
                        var company= '<?php echo $_GET["workingcompany"]; ?>';
                        var crudServiceBaseUrl = "../../data",
                            dataSource = new kendo.data.DataSource({
                                transport: {
                                    read:  {
                                        url: "http://www.northpier.org/data/fetchcap.php?company="+company,
                                        dataType: "json"
                                    },
     
     
    update:  {
     
                                        url: "http://www.northpier.org/data/Updatecap.php?company="+company,
                                        type: "PUT",
                                        dataType: "jsonp"
                           
    },
                                    destroy: {
                                        url: crudServiceBaseUrl + "/destroy.php",
                                        dataType: "json"
                                    },
                                    create: {
                                        url: crudServiceBaseUrl + "/create.php",
                                        dataType: "json"
                                    },
                                    parameterMap: function(options, operation) {
                                        if (operation !== "read" && options.models) {
                                            return {models: kendo.stringify(options.models)};
                                        }
                                    }
                                },
                                batch: true,
                                pageSize: 30,
                                schema: {
                                    model: {
     
     
                                                    id: "id",
     
                                        fields: {
                                            id: { type: "string", editable: false },
                                            date_time: { type: "string"},
                                            Name: { type: "string", editable: true },
                                            Common: { type: "number", validation: { required: true, min: 0} },
                                            SeriesA: { type: "number", validation: { required: true, min: 0} },
                                            SeriesB: { type: "number", validation: { required: true, min: 0} },
                                            SeriesC: { type: "number", validation: { required: true, min: 0} },
                                        }
     
     
                                    }
                                }
                            });
     
                        $("#grid").kendoGrid({
                            dataSource: dataSource,
     
    filterable:true,
     
    groupable:true,
     
                            navigatable: true,
                            pageable: true,
                            height: 400,
                            toolbar: ["create", "save", "update", "cancel"],
                            columns: [{
                                    field: "Name",
                                    title: "Name",
                                    editable: true,
                                },
                                {
                                    field: "Common",
                                    title: "Common",
                                },
                                {
                                    field: "SeriesA",
                                    title: "Series A",
                                },
                                {
                                    field: "SeriesB",
                                    title: "Series B",
                                },   
                                {
                                    field: "SeriesC",
                                    title: "Series C",
                                }],
     
      columnMenu:{
        messages:{
          columns:"Choose columns",
          filter:"Apply filter",
          sortAscending:"Sort (asc)",
          sortDescending:"Sort (desc)"
        }
      },
     
     
                            editable: true,
                           
     
                           change: function() {
                                console.log("change event");
                            },
                            edit: function() {
                                console.log("edit event");
                            },
                            save: function() {
                                console.log("save event");
                            },
                            saveChanges: function() {
                                console.log("saveChanges event");
                                  $('#grid').data().kendoGrid.refresh();
                            },
                            remove: function() {
                                console.log("remove event");
                            }
                        });
                    });
                </script>
            </div>
    <?php
    $dbhost = 'localhost:3036';
    $dbuser = 'XXXXXXXXXXXXX';
    $dbpass = 'XXXXXXXXXXXXXXX';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
      die('Could not connect: ' . mysql_error());
    }
    parse_str(file_get_contents("php://input"),$post_vars);
    $comp = $_GET['company'];
    $mod = $_GET['models'];
    $request = json_decode($mod);
     
    foreach ($request as $product) {
     
    $sql = "UPDATE captable
            SET Name='$product->Name',
            Common='$product->Common',
            SeriesA='$product->SeriesA',
            SeriesB='$product->SeriesB',
            SeriesC='$product->SeriesC'
            WHERE id='$product->id'";
     
    mysql_select_db('XXXXXXXXXXX');
    $retval = mysql_query( $sql, $conn );
     
    if(!$retval )
    {
      echo "OUCH!";
      //die('Could not update data: ' . mysql_error());
    }
    else
    {
            $result3 = null;
    echo $result3;
     
    }
    }
    mysql_close($conn);
     
     
    ?>
  2. Paweł Kasztelan
    Paweł Kasztelan avatar
    17 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2013 Link to this post

    update:  {
                                        url: "http://www.northpier.org/data/Updatecap.php?company="+company,
                                        dataType: "jsonp"
    },
    You really need to send a PUT method? Remove it and let it fly with the POST method.

    $sql = "UPDATE captable
            SET Name='{$product->Name}',
            Common='{$product->Common}',
            SeriesA='{$product->SeriesA}',
            SeriesB='{$product->SeriesB}',
            SeriesC='{$product->SeriesC}'
            WHERE id='{$product->id}';";
  3. Kendo UI is VS 2017 Ready
  4. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2565 posts

    Posted 14 Aug 2013 Link to this post

    Hi Joel,

    Did you try what Marek, suggested? Did it work? Your code look perfectly valid, so try with removing the PUT method and let us know if the problem still persists.

    Regards,
    Kiril Nikolov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top