Strange Behavior using MySQL

Here is my query:

$query = "UPDATE money SET value = '5' WHERE key = 'one'";

When I run the page, the query dies saying:

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 'key = 'one'' at
line 1

The same thing happens when I use INSERT or other functions. I have used
them before, but now I seem to be having troubles. Can anyone find any
mistakes? I'm running XAMPP 1.6.0a on a Windows machine.
Matt White [ Sa, 05 Mai 2007 01:00 ] [ ID #1705337 ]

Re: Strange Behavior using MySQL

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

--
Chris
http://www.veign.com / http://www.veign.com/blog
--
"Matt White" <mgw854 [at] msn.com> wrote in message
news:hWO_h.48$LJ3.27 [at] trnddc02...
> Here is my query:
>
> $query = "UPDATE money SET value = '5' WHERE key = 'one'";
>
> When I run the page, the query dies saying:
>
> 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 'key = 'one''
> at line 1
>
> The same thing happens when I use INSERT or other functions. I have used
> them before, but now I seem to be having troubles. Can anyone find any
> mistakes? I'm running XAMPP 1.6.0a on a Windows machine.
Veign [ Sa, 05 Mai 2007 04:24 ] [ ID #1705338 ]

Re: Strange Behavior using MySQL

Matt White wrote:
> Here is my query:
>
> $query = "UPDATE money SET value = '5' WHERE key = 'one'";

As you been using reserved words as column name this is how the query should
look like:
$query = "UPDATE money SET value = '5' WHERE `key` = 'one'";

Next time you create a table, do take a look at the page Veign posted and do
not use those column/table names that are listed there.
--

//Aho
Shion [ Sa, 05 Mai 2007 07:29 ] [ ID #1705339 ]

Re: Strange Behavior using MySQL

Thanks a lot! It now works. I didn't know that there were reserved words
in MySQL.

"J.O. Aho" <user [at] example.net> wrote in message
news:5a2j3qF2mpuglU1 [at] mid.individual.net...
> Matt White wrote:
>> Here is my query:
>>
>> $query = "UPDATE money SET value = '5' WHERE key = 'one'";
>
> As you been using reserved words as column name this is how the query
> should
> look like:
> $query = "UPDATE money SET value = '5' WHERE `key` = 'one'";
>
> Next time you create a table, do take a look at the page Veign posted and
> do
> not use those column/table names that are listed there.
> --
>
> //Aho
Matt White [ Sa, 05 Mai 2007 17:30 ] [ ID #1705340 ]

Re: Strange Behavior using MySQL

Safest thing is to assume there are always reserved words anything
development, which there are...

--
Chris
http://www.veign.com / http://www.veign.com/blog
--
"Matt White" <mgw854 [at] msn.com> wrote in message
news:pq1%h.477$wy2.253 [at] trnddc03...
> Thanks a lot! It now works. I didn't know that there were reserved words
> in MySQL.
>
> "J.O. Aho" <user [at] example.net> wrote in message
> news:5a2j3qF2mpuglU1 [at] mid.individual.net...
>> Matt White wrote:
>>> Here is my query:
>>>
>>> $query = "UPDATE money SET value = '5' WHERE key = 'one'";
>>
>> As you been using reserved words as column name this is how the query
>> should
>> look like:
>> $query = "UPDATE money SET value = '5' WHERE `key` = 'one'";
>>
>> Next time you create a table, do take a look at the page Veign posted and
>> do
>> not use those column/table names that are listed there.
>> --
>>
>> //Aho
>
Veign [ Sa, 05 Mai 2007 20:07 ] [ ID #1705341 ]
PHP » alt.php » Strange Behavior using MySQL

Vorheriges Thema: Function tables
Nächstes Thema: help with posting using conditional if