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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.