0

I am using X-Editable-Bootstrap to do some inline editing. Everything works but it's not updating the DB so I am wondering if I am doing something wrong.

Here's my 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!";
    }

Here's the response body from FireFox debugging:

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

JavaScript:

    $(function(){
        $.fn.editable.defaults.mode = 'inline';
        $('.editcontent').editable({
            url: 'post.php',
            title: 'Modify Entry'
        });
    });
John Guan
  • 744
  • 2
  • 11
  • 26
  • 1
    You are attempting to use a column name as a bound parameter in your query, which won't work: parameters have to be *data*, not identifiers. See http://stackoverflow.com/q/182287/157957 – IMSoP Sep 27 '13 at 22:54
  • 1
    Also, a tip for debugging: since an AJAX call is just a web request, you can take all the JS away and load the web request in a browser tab, then add debugging output to it just like you would a normal page. Doing that here would have allowed you to narrow it down to the SQL, and not bother showing us the rest of the code. – IMSoP Sep 27 '13 at 22:57

0 Answers0