0

PDO を使用してデータベースにデータを保存/更新する際に問題があります。

この関数は私のデータを保存します:

    function saveOrder($position,$id) {
    $sql = '
    UPDATE 
        '.DBPREFIX.'section_2 
    SET 
        order = ?
    WHERE 
        id = ?';
    $stmt = $this->db->prepare($sql);  
    $stmt->execute(array($position,$id));
    return var_dump($stmt->errorInfo());
}  

これは sort_2.php です:

$VAR_BACK = "../";
include($VAR_BACK."_config.php");
include($VAR_BACK."_config_db.php");
include($VAR_BACK."_functions.php");
include($VAR_BACK."_start.php");
include_once("../classes/helper.class.php");
$helper = new helper();

foreach ($_GET['item'] as $position => $item)
{
    $helper->saveOrder($position,$item);
}

これは私のフロントエンドphpファイルにあります:

         <script>
// Return a helper with preserved width of cells
var fixHelper = function(e, ui) {
    ui.children().each(function() {
        $(this).width($(this).width());
    });
    return ui;
};

$(document).ready(function(){
    $("#sort tbody").sortable({
        helper: fixHelper,
        update : function () { 
                var data = $(this).sortable('serialize');
                //$('#info').text(data);
                $("#info").load("sort_2.php?"+data);
            } 
    }).disableSelection();
});

そして私はいつもこのメッセージを受け取ります:

string(178) "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order = '2'
    WHERE 
        id = '1'' at line 4"  

4 行目:
order = ?

しかし、ここでエラーが発生する可能性があるかどうかはわかりません。(int)にキャストしようとしましたが、ストリップスラッシュを試しましたが、何も機能しませんでした。

DB の列は次のとおりです: id = int(5) および order = varchar(10)

助言がありますか?ありがとう。

4

1 に答える 1