This is a migrated thread and some comments may be shown as answers.

Update mysql with batch grid not updating

2 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
johaswe
Top achievements
Rank 1
johaswe asked on 13 Aug 2013, 05:00 AM
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 Answers, 1 is accepted

Sort by
0
Paweł Kasztelan
Top achievements
Rank 2
answered on 13 Aug 2013, 06:26 AM
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}';";
0
Kiril Nikolov
Telerik team
answered on 14 Aug 2013, 11:21 AM
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!
Tags
Grid
Asked by
johaswe
Top achievements
Rank 1
Answers by
Paweł Kasztelan
Top achievements
Rank 2
Kiril Nikolov
Telerik team
Share this question
or