xorinzor
xorinzor

Reputation: 6467

MySQL Update not updating any rows

This is a weird issue I'm having, I have a table and try to do a MySQL-Update query, however, PHPMyAdmin keeps saying 0 rows affected.

Table:

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `userid` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `last_login` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=55069 ;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `userid`, `name`, `last_login`) VALUES
(1, 55068, 'temp', '2012-02-02 09:04:50');

Query:

UPDATE `users` SET name='xorinzor' AND last_login=NOW() WHERE userid='55068'

No errors are returned, just nothing is happening, got no clue why that would be.

Regards, Jorin

Upvotes: 1

Views: 8035

Answers (1)

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181350

Change your update sentence to:

UPDATE `users` SET password='encryptedthingy', name='xorinzor', last_login=NOW() 
 WHERE userid=55068

Your SQL syntax was wrong. If you want to update multiple fields at once, you should not separate them with and keyword but with ,.

Also, make getting rid of single quotes for '55068' should help, since that column is a number. And '55068' is a string literal.

Make sure this sentence returns a value:

select * from `users` where userid=55068

Upvotes: 7

Related Questions