我正在使用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);
答案 0 :(得分:0)
存在语法错误 “',”。$ _ POST ['phone']。“”); =&GT;我应该是'','“。$ _ POST ['phone']。”'“); //如果是int,那么没关系
您可能需要使用mysql_escape_string()删除那里的任何特殊字符。