Carl Miller
Carl Miller

Reputation: 142

SQL syntax error using UPDATE/SET

The error I receive: 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 'release=2012-09-02, platforms=Android, link=`play.php?game=G' at line 6

The code:

$sql = "UPDATE
            GameInformation
        SET
            keyIndex=`GameTest`,
            name=`Game Test`,
            release=`2012-09-02`,
            platforms=`Android`,
            link=`play.php?game=GameTest`,
            icon=`img/thumb_gametest.png`,
            thumb=`img/thumb_mini_gametest.png`,
            swf=`swf/GameTest.swf`,
            height=`500`,
            width=`920`
        WHERE
            keyIndex=`GameTest2`";

$query = mysql_query($sql);

if (!$query) exit (mysql_error());

I've been trying different delimiters (braces, apostrophes, quotes) around my set vars with no avail. Is there a reserved word in here?

Update [Solved], corrected code:

$sql = 'UPDATE
                            `GameInformation`
                        SET
                            `keyIndex`="GameTest",
                            `name`="Game Test",
                            `release`="2012-09-02",
                            `platforms`="Android",
                            `link`="play.php?game=GameTest",
                            `icon`="img/thumb_gametest.png",
                            `thumb`="img/thumb_mini_gametest.png",
                            `swf`="swf/GameTest.swf",
                            `height`="500",
                            `width`="920"
                        WHERE
                            `keyIndex`="GameTest2"';
            $query = mysql_query($sql);
            if (!$query) exit (mysql_error());

Upvotes: 0

Views: 156

Answers (2)

jmilloy
jmilloy

Reputation: 8355

release is a reserved word in mysql.

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Upvotes: 0

Sergey Eremin
Sergey Eremin

Reputation: 11080

You should use ` for table and column names and " or ' for content. RELEASE is a reserved word.

UPDATE
            `GameInformation`
        SET
            `keyIndex`="GameTest",
            `name`="Game Test",
            `release`="2012-09-02",
            `platforms`="Android",
            `link`="play.php?game=GameTest",
            `icon`="img/thumb_gametest.png",
            `thumb`="img/thumb_mini_gametest.png",
            `swf`="swf/GameTest.swf",
            `height`="500",
            `width`="920"
        WHERE
            `keyIndex`="GameTest2"

Upvotes: 5

Related Questions