PDA

View Full Version : Help with MySQL UPDATE


techlinks
10-20-07, 10:35 PM
Hello Folks:

OK, so I'm new to SQL but can't for the life of me find the syntax error in the following SQL statement. Can someone point to where I've messed up? It is:

UPDATE homenews SET subject = 'aaaa', description = ' bbb ', active = 'no', lastmodified = '2007-10-20' WHERE index = 101

MySQL keeps failing to execute; saying my SQL statement is invalid. The table definition is as follows:

CREATE TABLE `homenews` (
`index` int(3) NOT NULL auto_increment,
`subject` varchar(20) NOT NULL,
`description` varchar(20) NOT NULL,
`image` varchar(20) NOT NULL,
`lastmodified` date NOT NULL,
`active` varchar(3) NOT NULL,
PRIMARY KEY (`index`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=102 ;


Thanks in advance everyone.

Lester

Neat Pete
10-21-07, 12:00 AM
You must set a value for `image` because you have defined it as NOT NULL.

techlinks
10-21-07, 01:47 PM
Thanks you. It did the trick. Also, because index is a reserved word.. I used `index` instead in my query.

Neat Pete
10-21-07, 06:10 PM
Good thinking. It's not the index anyway, it's the primary key. The name used for the field by the professionals would normally be HomeNewsID. You might prefer to do it in all lower case.