我正在使用 jtable 来帮助用户管理联系表单,但是我无法使用 CreateAction.php 将数据插入到 mysql 表中,首页代码如下:
<script type="text/javascript">
$(document).ready(function () {
$('#PersonTableContainer').jtable({
title: 'Contact list',
actions: {
listAction: '/Pipit/assets/php/list.php',
createAction: '/Pipit/assets/php/createAction.php',
updateAction: '/Pipit/assets/php/edit.php',
deleteAction: '/Pipit/assets/php/delete.php'
},
fields: {
personID: {
key: true,
list: false
},
name: {
title: 'name',
},
group: {
title: 'group',
},
phone: {
title: 'number',
}
}
});
createAction.php 文件如下:
//Insert record into database
$insert=mysql_query("INSERT INTO pipit_contacts (name, group, phone) VALUES('" . $_POST["name"] . "', '" . $_POST["group"] . "', ".$_POST['phone']."");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM pipit_contacts ORDER BY personID DESC ");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);