0

我正在使用 X-Editable-Bootstrap 进行一些内联​​编辑。一切正常,但它没有更新数据库,所以我想知道我是否做错了什么。

这是我的post.php

require_once("config.php");
    $pk = $_POST['pk'];
    $name = $_POST['name'];
    $value = $_POST['value'];

    if(!empty($value)) {
        try {
            $dbh = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME, DB_USER, DB_PASS);
            $sth = $dbh->prepare('UPDATE qa_tbl SET ?=? WHERE id = ?');
            $sth->execute(array($name,$value,$pk));
        } catch (PDOException $e) {
            print "Error!: " . $e->getMessage() . "<br/>";
            die();
        }
        print_r($_POST);
    } else {
        header('HTTP 400 Bad Request', true, 400);
        echo "This field is required!";
    }

这是 FireFox 调试的响应正文:

Array
(
    [name] => Question
    [value] => Yes
    [pk] => 2
)

JavaScript:

    $(function(){
        $.fn.editable.defaults.mode = 'inline';
        $('.editcontent').editable({
            url: 'post.php',
            title: 'Modify Entry'
        });
    });
4

0 回答 0