...

View Full Version : Duplicate entry at 3 primaery key field...



hanpedro
07-01-2005, 05:07 PM
When inserting data to 3 primary key field, error comes.

"Duplicate entry 'test_col-0-0' for key 1"

##
## Table structure for table `test_table`
##

CREATE TABLE test_table (
t_case varchar(20) NOT NULL default '',
att int(11) NOT NULL default '0',
law int(11) NOT NULL default '0',
book varchar(255) NOT NULL default '',
asfile varchar(255) NOT NULL default '',
tt-frm varchar(255) NOT NULL default '',
contct text NOT NULL,
PRIMARY KEY (t_case,att,law)
) TYPE=MyISAM;


$sql = " insert into test_table
set bo_table = ww_co,
t_case = '$row[idx]',
att = '$att',
book = '$book',
tt-frm = '$tt-frm',
contct = '$row[contct]' ";
mysql_query($sql);

Please understand I am beginner of English and php.
And I could not ask what is problem for this.

Fisrt of all, I want to know where 'test_col-0-0' is.

Any comment would be appreciated.

Kid Charming
07-01-2005, 05:55 PM
A primary key index must be unique -- the duplicate entry error comes when you try to enter a value (or series of values, for a multi-column index) that already exist. 'Test_col', '0', and '0' are values that you've already entered into the db -- Test_col is the value of t_case, and the 0's are both defaults for att and law. So you're either trying to run an INSERT you've already run, or your $att variable isn't being set correctly (and you're not inserting a law value at all, which makes me wonder if it really should be part of the PK).

hanpedro
07-02-2005, 01:59 AM
Dear Kid Charming,

Thanks very much for your detailed explanation.
I will study and report you.



A primary key index must be unique -- the duplicate entry error comes when you try to enter a value (or series of values, for a multi-column index) that already exist. 'Test_col', '0', and '0' are values that you've already entered into the db -- Test_col is the value of t_case, and the 0's are both defaults for att and law. So you're either trying to run an INSERT you've already run, or your $att variable isn't being set correctly (and you're not inserting a law value at all, which makes me wonder if it really should be part of the PK).

hanpedro
07-02-2005, 03:13 PM
CREATE TABLE test_table (
t_case varchar(20) NOT NULL default '',
att int(11) NOT NULL default '0',
law int(11) NOT NULL default '0',
book varchar(255) NOT NULL default '',
asfile varchar(255) NOT NULL default '',
tt-frm varchar(255) NOT NULL default '',
contct text NOT NULL,
PRIMARY KEY (t_case,att,law)
) TYPE=MyISAM;


$sql = " insert into test_table
set bo_table = ww_co,
t_case = '$row[idx]',
att = '$att',
law = '$law',
book = '$book',
tt-frm = '$tt-frm',
contct = '$row[contct]' ";
mysql_query($sql);

echo "$row[idx]";
echo "att";
echo "law";

And,
row[idx] = test_col
att = 0
law = 1

However, the result is still
Duplicate entry 'test_col-0-0' for key 1

What does this mean?

Kid Charming
07-02-2005, 05:35 PM
Echo your entire query, and see what that gives you.

hanpedro
07-03-2005, 05:43 AM
Echo your entire query, and see what that gives you.

Sorry, I've mistyped in loop sentence.

Thanks a lot Kid.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum