Jump to content

PRIMARY KEY


bamfon

Recommended Posts

My primary key is not working its letting the same name "king" or anyother name i enter in to the database more then once :S

 

eported database info

CREATE TABLE IF NOT EXISTS `anime1` (
  `id` int(15) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `type` varchar(255) NOT NULL,
  `episode` varchar(255) NOT NULL,
  `year` varchar(255) NOT NULL,
  `genre` varchar(255) NOT NULL,
  `status` varchar(255) NOT NULL,
  `summary` mediumtext,
  `pictures` varchar(255) NOT NULL,
  PRIMARY KEY (`id`,`title`,`pictures`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

--
-- Dumping data for table `anime1`
--

INSERT INTO `anime1` (`id`, `title`, `type`, `episode`, `year`, `genre`, `status`, `summary`, `pictures`) VALUES
(1, 'king', 'king', '', '', '', '', '', ''),
(2, 'king', 'king', 'king', 'king', '', '', '', ''),
(3, 'king', 'kingking', '', '', '', '', '', ''),
(4, 'king', 'kingking', '', '', '', '', '', ''),
(5, 'king', 'kingking', '', '', '', '', '', ''),
(6, '', '', '', '', '', '', '', ''),
(7, 'king', 'kingking', '', '', '', '', '', ''),
(8, 'king', 'kingking', '', '', '', '', '', ''),
(9, '<php ?>', 'kingking', '', '', '', '', '', '');

 

i am using normale

[cod]

$sql="INSERT INTO anime1

(title, type, episode, year, genre, status, summary, pictures)

VALUES

('$title','$type','$episode','$year','$genre','$status','$summary','$pictures')";

[/code]

Link to comment
https://forums.phpfreaks.com/topic/224271-primary-key/
Share on other sites

PRIMARY KEY (`id`,`title`,`pictures`)

 

That's a compost key, made up of those three fields. As long as your id is different in each row, the compost key made up of `id`,`title`,`pictures` is different.

 

You would need to create a separate key just for the title.

Link to comment
https://forums.phpfreaks.com/topic/224271-primary-key/#findComment-1158718
Share on other sites

There are more than a few different reasons why a query will fail, not just due to a duplicate key.

 

In your error checking and error reporting logic, you would need to test the value that mysql_errno returns and if it is the value for a duplicate key (which I think is 1062, but you should check to confirm), you would output your custom message and continue with your code that is inserting values.

 

Link to comment
https://forums.phpfreaks.com/topic/224271-primary-key/#findComment-1159001
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.