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.
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);
?>