Jaswinder Kaur
Jaswinder Kaur

Reputation: 200

Syntax error in update when using where clause

I'm stuck in an update query. I'm working on registration form where if confirm mail link is been redirected to site then update query pass and update row with confirm value.

Here is the error message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''users' SET 'confirm'='1' WHERE 'com_code'='732aabcb4ad6a03b51e0a55aab998726'' at line 1

Please check where my syntax is wrong:

UPDATE 'users' 
SET 'confirm'='1' 
WHERE 'com_code'='732aabcb4ad6a03b51e0a55aab998726';

Thanks!

Upvotes: 0

Views: 872

Answers (2)

WAQ
WAQ

Reputation: 2626

You don't need to put confirm, users and com_code inside quotes, use this:

UPDATE users 
SET confirm ='1' 
WHERE com_code='732aabcb4ad6a03b51e0a55aab998726';

Upvotes: 0

Lukasz Szozda
Lukasz Szozda

Reputation: 175676

To quote identifiers use backticks ` Identifier Names

Identifiers may be quoted using the backtick character - `. Quoting is optional for identifiers that don't contain special characters, or is a reserved word. If the ANSI_QUOTES SQL_MODE flag is set, double quotes (") can also be used to quote identifiers.

UPDATE `users` 
SET `confirm`='1' 
WHERE `com_code`='732aabcb4ad6a03b51e0a55aab998726';

or don't use them at all if your identifiers aren't keywords or don't contains spaces and so on:

UPDATE users 
SET confirm ='1' 
WHERE com_code='732aabcb4ad6a03b51e0a55aab998726';

Upvotes: 4

Related Questions