kendo UI グリッドを使用して Mysql に接続すると、関数の更新と読み取りは問題ありませんが、create を使用して新しい行にデータを入力すると、更新をクリックしますが、手間がかかりません。何が悪いのかわからない?私のグリッドは次のとおりです。
$("#grid").kendoGrid({
dataSource: {
transport: {
read: "data/channels.php",
update: {
url: "data/channels.php",
type: "POST"
},
create: {
dataType: "json",
url: "data/channeladd.php",
type: "POST"
}
},
schema: {
data: "results",
model: {
id: "channelId",
fields: {
channelName: { validation: { required: true} }
}
}
}
},
columns: [{ field: "channelName", title: "Channel Name" }, { field: "channelIp", title: "Channel Ip" }, { field: "channelPort", title: "Channel Port" }, { command: ["edit", "destroy"], title: " ", width: "172px" }],
editable: "inline",
navigable: true, // enables keyboard navigation in the grid
toolbar: [ "create" ] // adds save and cancel buttons
});
そして channeladd.php で:
$link = mysql_pconnect("localhost", "root", "THE PASSWORD") or die("Unable To Connect To Database Server");
mysql_select_db("THE DB") or die("Unable To Connect To THE DB");
// add the header line to specify that the content type is JSON
header("Content-type: application/json");
$request = json_decode(file_get_contents('php://input'));
// 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.
$channelnName = $request["channelName"];
$channelnIp = $request["channelIp"];
$channelnPort = $request["channelPort"];
$sql = "INSERT INTO channel (channelName, channelIp, channelPort) VALUES (".$channelnName.",".$channelnIp.",".$channelnPort.")";
$rs = mysql_query($sql);
if ($rs) {
echo true;
}
else {
header("HTTP/1.1 500 Internal Server Error");
echo false;
}
アドバイスをいただければ幸いです。