Carl K
Carl K

Reputation: 984

MySQL Update Statement Returning No Affected Rows

I'm struggling to find an error in this. I am running an Update command in MySQL through PHP.

UPDATE `diary` SET `meds_taken` = 'Y' AND `time_taken` = '9AM' AND 
`stress_level` = '7' AND `adverse` = 'N' AND `events` = 'testing' AND 
`journal_date` = '2015-07-14' AND `submit_time` = NOW() WHERE `hash` = 
'a9fc195dc62624db5fddd7134392ce67'

It does not return any errors, but affects 0 rows. Running the command directly in PHPMyAdmin has the identical effect.

To confirm, there is a row with the hash:

SELECT * FROM `diary` WHERE `hash` = 'a9fc195dc62624db5fddd7134392ce67'

Yields one row. All the updated columns are of type VARCHAR except for "events" which is of type TEXT and "submit_time" which is of type DATE.

I feel like I made a typo somewhere but cannot find it

Upvotes: 0

Views: 35

Answers (1)

Luke
Luke

Reputation: 1724

Try commas, rather than ANDs:

UPDATE `diary`
SET `meds_taken` = 'Y',
    `time_taken` = '9AM',
    `stress_level` = '7',
    `adverse` = 'N',
    `events` = 'testing',
    `journal_date` = '2015-07-14',
    `submit_time` = NOW()
WHERE `hash` = 'a9fc195dc62624db5fddd7134392ce67';

Upvotes: 1

Related Questions