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

Kendo UI Grid, does not update the database.

1 Answer 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
wainman
Top achievements
Rank 1
wainman asked on 04 Apr 2013, 12:02 PM
I cant make the grid to update de database. i press the save button and it does nothing. 

Code for the grid: 

<!DOCTYPE html>
<html>
<head>
    <title>Customizing filter menu</title>

<link href="/styles/kendo.common.min.css" rel="stylesheet">
<link href="/styles/kendo.default.min.css" rel="stylesheet">

<script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="/js/kendo.all.min.js"></script>
<script type="text/javascript" src="/js/people.js"></script>

<style>
.k-grid {
margin: 5px;
}
</style>
</head>
<body>
<div id="grid"></div>
        <script>
$(function() {
            $("#grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: "data.php",
update: {
                url: "data.php",
                type: "POST"
}
                    },
       
                    schema: {
                        data: "data",
                        model: {
codmat: "codmat",
fields: {
                  codmat: { editable: false }, 
codarea:{ editable: false },
codrubro:{ editable: false },
codsubrub:{ editable: false },
secuencia:{ editable: false },
nombre:{ editable:true},
}
}
}
                },
                columns: [{ field: "codmat" }, { field: "codarea" }, { field: "codrubro" }, { field: "codsubrub" }, { field: "secuencia"}, { field: "nombre" }],

    editable: true,
navigable: true, //habilita el teclado para navegar
toolbar: ["save", "cancel"]//adds save and cancel buttons
            }); 
        });
        </script> 
</body>
</html>


Code for the database:




<?php

    $link = mysql_pconnect("localhost", "root", "") or die("Unable To Connect To Database Server");
   mysql_select_db("datos") or die("Unable To Connect To Northwind");

 
 // add the header line to specify that the content type is JSON
    header("Content-type: application/json");

    // determine the request type
    $verb = $_SERVER["REQUEST_METHOD"];

    // handle a GET 
    if ($verb == "GET") {
        $arr = array();

        $rs = mysql_query("SELECT codmat, codarea, codrubro, codsubrub, secuencia, nombre FROM mater");

        while($obj = mysql_fetch_object($rs)) {

            $arr[] = $obj;

        }
        echo "{\"data\":" .json_encode($arr). "}";
    }

// handle a POST  
    if ($verb == "POST") {

 // DISCLAIMER: It is better to use PHP prepared statements to communicate with the database. 
        //             this provides better protection against SQL injection.
        //             [http://php.net/manual/en/pdo.prepared-statements.php][4]
        // get the parameters from the post. escape them to protect against sql injection.

        $codmat = mysql_real_escape_string($_POST["codmat"]);
$nombre = mysql_real_escape_string($_POST["nombre"]);
        $rs = mysql_query("UPDATE mater SET nombre = '" . $nombre ."' WHERE codmat = " .$codmat);
if ($rs) {
        echo json_encode($rs);
    }
    else {
        header("HTTP/1.1 500 Internal Server Error");
        echo "Update failed for EmployeeID: " .$employeeId;
    }

}
 ?>

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 05 Apr 2013, 01:29 PM
Hi Wainman,


From the provided information it's not clear for us what is the exact reason for this behavior - could you please provide the following details? 
This would help us pinpoint the exact reason for this behavior.

Kind regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
wainman
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or