-3

你好我有这个插入数据的功能:

function add_item($id, $name, $level, $img, $health, $mana, $stamia, $str, $int, $luc, $information, $gold, $tradeable, $faction)
{
    if (isset($_SESSION['admin']))
    {
        global $pdo;

        $check = $pdo->prepare("SELECT * FROM items WHERE item_id = :id AND item_name = :name");
        $check->execute(array(":id" => $id, ":name" => $name));

        /**
        * Checking if row doesn't exists
        **/

        if (!$check->rowCount())
        {           
            $insert = $pdo->prepare
            ("
            INSERT INTO items 
            (item_id, item_name, item_level, item_thumbnail, date, time, health, mana, stamia, str, int, luc, information, tradeable, faction, price) 
            VALUES
            (:id, :name, :level, :img, CURDATE(), CURTIME(), :health, :mana, :stamia, :str, :int, :luc, :information, :tradeable, :faction, :price)
            ");
                $insert->execute(array
                (
                ":id" => $id,
                ":name" => $name,
                ":level" => $level,
                ":img" => $img,
                ":health" => $health,
                ":mana" => $mana,
                ":stamia" => $stamia,
                ":str" => $str,
                ":int" => $int,
                ":luc" => $luc,
                ":information" => $information,
                ":tradeable" => $tradeable,
                ":faction" => $faction,
                ":price" => $gold
                ));
        }
}

但是在它处理之后,我得到了这个错误:

SQLSTATE[42000]: Syntax error or access violation: 1064 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 'int, luc, information, tradeable, faction, price) VALUES ('34434', 'dre' at line 2

一切似乎都是正确的?..那里有什么问题?我看不出查询语法有任何问题。

谢谢。

4

2 回答 2

3

int此保留关键字列表中的关键字;所以你不能在你的查询中使用它;尝试将其包装在反引号中:

INSERT INTO items (item_id, ..., `int`, ...)
于 2013-04-27T14:09:08.830 回答
0

在 mysql 中,int是一个保留字,因此如果你有一个名为 的列int,你需要反引号它:..., `int`, ...

于 2013-04-27T14:10:00.110 回答