Man... I feel like such a noob. "Duplicate Key" e

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Man... I feel like such a noob. "Duplicate Key" e

Post by Steveo31 »

I don't think thats a bad thing, but nonetheless, I looked up the solution to this prob with no avail.

That stupid error of "duplicate key '0' in" or whatever came up.

DB:

Code: Select all

CREATE TABLE `articles` (
  `id` int(5) NOT NULL auto_increment,
  `title` varchar(50) NOT NULL default '',
  `body` text NOT NULL,
  `author` varchar(40) NOT NULL default '',
  `dateadd` datetime NOT NULL default '0000-00-00 00:00:00',
  `rating` tinyint(2) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `rating` (`rating`),
  KEY `author` (`author`),
  FULLTEXT KEY `body` (`body`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
Insert code:

Code: Select all

$insert = mysql_query("INSERT INTO `articles` (`title`, `body`, `author`, `dateadd`) VALUES ('$title', '$body', '$author', NOW())");
:?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

rating is a unique key.. and you aren't setting it. It's default is 0.. so yeah..
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

Doh.

Thanks :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hehe easy mistake. ;)
Post Reply