Sibidharan Sibidharan - 4 months ago 4x
MySQL Question

Why UPDATE query not working

Here is my code

UPDATE project SET name = 'New Name' AND platform = 'iOS' WHERE id = 2

When I process it via phpMyAdmin, it is changing the name to
. When I rerun the query, it says 0 rows affected. When I change back the name to something else and rerun the query, it says 1 row affected, but changing the name back to 0 and nothing else.

What am I doing wrong?

I have the table with proper structure and have a record with


Your UPDATE syntax is wrong. It should be this:

UPDATE project SET name = 'New Name', platform = 'iOS' WHERE id = 2

MySQL is changing name to 0 because it is confused about what you mean by AND. It's possible MySQL is interpreting that statement to be a logical expression, which gets converted into a 1 for TRUE or a 0 for FALSE (in this case, the latter).

Think of your original query like this, with parentheses used to illustrate operator precedence:

UPDATE project SET name = ('New Name' AND (platform = 'iOS')) WHERE id = 2