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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    217
    Thanks
    1
    Thanked 0 Times in 0 Posts

    whats this error about ??

    Hello forums!!
    I tried to insert following query in the table called user_table
    PHP Code:
    INSERT INTO user_table (id,username,realname,email,password,date_created
    VALUES
    ('','user1','user name','user1@localhost','1a1dc91c907325c69271ddf0c944bc72',now()) 
    I got the following errors(in Phpmyadmin):
    Error

    Code:
    SQL query:
    
    INSERT INTO mantis_user_table( id, username, realname, email,
    PASSWORD , date_created )
    VALUES (
    '', 'user1', 'user 111', 'rajen@localhost1', '1a1dc91c907325c69271ddf0c944bc72', now( )
    )
    
    MySQL said: Documentation
    #1062 - Duplicate entry '' for key 2
    My table structure is:
    Code:
    CREATE TABLE `user_table` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `username` varchar(32) collate latin1_general_ci NOT NULL default '',
      `realname` varchar(64) collate latin1_general_ci NOT NULL default '',
      `email` varchar(64) collate latin1_general_ci NOT NULL default '',
      `password` varchar(32) collate latin1_general_ci NOT NULL default '',
      `date_created` datetime NOT NULL default '1970-01-01 00:00:01',  
      PRIMARY KEY  (`id`),
      UNIQUE KEY `idx_user_cookie_string` (`cookie_string`),
      UNIQUE KEY `idx_user_username` (`username`),
      KEY `idx_enable` (`enabled`),
      KEY `idx_access` (`access_level`)
    );
    I am unable to figure out the problems
    Please help!!
    Thanks in advance to all of you.
    Last edited by guelphdad; 04-01-2007 at 01:59 PM. Reason: added proper tags

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    two things. number one, leave your auto increment column out of the insert entirely, don't name that column and don't insert a value into it.

    second the key 2 means your second column, so you are trying to insert a value that already exists there when you have defined a unique key on that column.


  •  

    Posting Permissions

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