This question is locked. New answers and comments are not allowed.
i always get this undefined index error whenever i try to insert, update or delete from a grid....using php via json...please can someone help out. and how do i name my form element in the grid? thanks
code below:
if ($verb == "PUT") {
// 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 get. escape them to protect against sql injection.
$employeeId = mysql_real_escape_string($_POST["EmpId"]);
$firstName = mysql_real_escape_string($_POST["Fname"]);
$rs = mysql_query("INSERT INTO users (EmpId,Fname) VALUES ('" .$employeeId. "','" .$firstName ."')");
if ($rs) {
echo json_encode($rs);
}
else {
header("HTTP/1.1 500 Internal Server Error");
echo "Insert Failed";
}
}
<script>
$(document).ready(function () {
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "data/users.php",
dataType: "json",
type:"GET"
},
update: {
url: "data/users.php",
dataType: "json",
type:"POST"
},
create: {
url: "data/users.php",
dataType: "json",
type:"PUT"
},
destroy: {
url: "data/users.php",
dataType: "json",
type: "DELETE"
}
},
error: function(e) {
alert(e.responseText);
},
schema: {
data:"data",
total:"total",
model: {
fields:{ Fname: { validation: { required: true} }
}
}
},
pageSize: 10
});
$("#grid").kendoGrid({
dataSource: dataSource,
height: 430,
pageable: true,
toolbar: ["create"],
columns: [{field: 'EmpId', title: 'EmployeeID'},
{field: 'Fname', title: 'FirstName'},
{ command: ["edit", "destroy"], title: " ", width: "160px" }],
editable:"popup"
});
});
</script>
code below:
if ($verb == "PUT") {
// 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 get. escape them to protect against sql injection.
$employeeId = mysql_real_escape_string($_POST["EmpId"]);
$firstName = mysql_real_escape_string($_POST["Fname"]);
$rs = mysql_query("INSERT INTO users (EmpId,Fname) VALUES ('" .$employeeId. "','" .$firstName ."')");
if ($rs) {
echo json_encode($rs);
}
else {
header("HTTP/1.1 500 Internal Server Error");
echo "Insert Failed";
}
}
<script>
$(document).ready(function () {
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "data/users.php",
dataType: "json",
type:"GET"
},
update: {
url: "data/users.php",
dataType: "json",
type:"POST"
},
create: {
url: "data/users.php",
dataType: "json",
type:"PUT"
},
destroy: {
url: "data/users.php",
dataType: "json",
type: "DELETE"
}
},
error: function(e) {
alert(e.responseText);
},
schema: {
data:"data",
total:"total",
model: {
fields:{ Fname: { validation: { required: true} }
}
}
},
pageSize: 10
});
$("#grid").kendoGrid({
dataSource: dataSource,
height: 430,
pageable: true,
toolbar: ["create"],
columns: [{field: 'EmpId', title: 'EmployeeID'},
{field: 'Fname', title: 'FirstName'},
{ command: ["edit", "destroy"], title: " ", width: "160px" }],
editable:"popup"
});
});
</script>