-3

Hello I have this function that inserts data:

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
                ));
        }
}

But after it processes, I get this error:

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

Everythig seems to be correct?.. What is wrong there? I can't see anythign wrong with the query syntax.

Thanks.

user2326532
  • 43
  • 1
  • 2
  • 7

2 Answers2

3

int is a keyword in this list of reserved keywords; so you cannot use it as is in your query; try to wrap it in backticks:

INSERT INTO items (item_id, ..., `int`, ...)
bwoebi
  • 23,637
  • 5
  • 58
  • 79
0

In mysql, int is a reserved word, therefore if you have a column named int, you need to backquote it: ..., `int`, ...

Aleks G
  • 56,435
  • 29
  • 168
  • 265