0

我正在使用 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);
4

1 回答 1

0

存在语法错误 "', ".$_POST['phone'].""); => 我应该是"','".$_POST['phone']."'");//如果是int,那么就可以了

您可能需要使用 mysql_escape_string() 来删除那里的任何特殊字符。

于 2013-11-14T07:02:23.257 回答