Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Cool

    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.
    Last edited by hanpedro; 07-01-2005 at 05:27 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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).

  • #3
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Dear Kid Charming,

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


    Quote Originally Posted by Kid Charming
    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).

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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?

  • #5
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Echo your entire query, and see what that gives you.

  • #6
    New Coder
    Join Date
    Jun 2005
    Posts
    91
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by Kid Charming
    Echo your entire query, and see what that gives you.
    Sorry, I've mistyped in loop sentence.

    Thanks a lot Kid.
    Last edited by hanpedro; 07-03-2005 at 09:07 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •