View Single Post
Join Date: Apr 2008
Posts: 35
Reputation: cali_dotcom is an unknown quantity at this point 
Solved Threads: 0
cali_dotcom cali_dotcom is offline Offline
Light Poster

Duplicate entry '' for key 2

 
0
  #1
Nov 17th, 2008
hi everyone,
i keep on getting this error when i try to insert a value into a table via php.
Duplicate entry '' for key 2

i've tried a lot of solutions from the web including changing the the primary key from int to bigint. i also flushed the database and deleted all entries from the database but i still got that error. i could insert records from the nysql command prompt but not from the php script.
does anyone know what might be wrong?
the table in question looks like this:

  1. CREATE TABLE `article_fields` (
  2. `id` INT(11) NOT NULL AUTO_INCREMENT,
  3. `field_title` VARCHAR(75) NOT NULL,
  4. `field_type` VARCHAR(75) NOT NULL,
  5. PRIMARY KEY (`id`)
  6. ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


and my php code to insert data into the table looks like this:
  1. $sql = 'INSERT INTO article_fields VALUES("NULL","'.$new_text.'","'.$field_type.'")';
  2. $insert = mysql_query($sql) or die(mysql_error());
Last edited by peter_budo; Nov 20th, 2008 at 12:42 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote